@@ -103,7 +103,12 @@ linalg.inv(B) # Inverse of identity is identity
103103```
104104
105105``` {code-cell} ipython3
106- linalg.eigh(B) # Computes eigenvalues and eigenvectors
106+ out = linalg.eigh(B) # Computes eigenvalues and eigenvectors
107+ out.eigenvalues
108+ ```
109+
110+ ``` {code-cell} ipython3
111+ out.eigenvectors
107112```
108113
109114### Differences
@@ -233,7 +238,7 @@ If we use the same key again, we initialize at the same seed, so the random numb
233238random.normal(key, (3, 3))
234239```
235240
236- To produce a (quasi-) independent draw, best practice is to " split" the existing key:
241+ To produce a (quasi-) independent draw, we can ` split ` the existing key.
237242
238243``` {code-cell} ipython3
239244key, subkey = random.split(key)
@@ -247,14 +252,22 @@ random.normal(key, (3, 3))
247252random.normal(subkey, (3, 3))
248253```
249254
255+ As we will see, the ` split ` operation is particularly useful for parallel
256+ computing, where independent sequences or simulations can be given their own
257+ key.
258+
259+ Another option is ` fold_in ` , which produces new "independent" keys from a base
260+ key.
261+
250262The function below produces ` k ` (quasi-) independent random ` n x n ` matrices using this procedure.
251263
252264``` {code-cell} ipython3
265+ base_key = random.PRNGKey(42)
253266def gen_random_matrices(key, n, k):
254267 matrices = []
255- for _ in range(k):
256- key, subkey = random.split(key)
257- matrices.append(random.uniform(subkey , (n, n)))
268+ for i in range(k):
269+ key = random.fold_in(base_key, i) # generate a fresh key
270+ matrices.append(random.uniform(key , (n, n)))
258271 return matrices
259272```
260273
0 commit comments