Skip to content

Commit f307a5d

Browse files
committed
DOC: Update randn() to use rng.normal()
Updates all references to `randn` to use `normal` from Generator. I left the matlib versions alone. In a few spots I added `seed=123`. I removed the `# may vary` tag from all examples. I reformatted some longer outputs to use Jupyter style output. [skip actions] [skip azp] [skip cirrus]
1 parent 501fecf commit f307a5d

File tree

9 files changed

+29
-32
lines changed

9 files changed

+29
-32
lines changed

numpy/_core/shape_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def stack(arrays, axis=0, out=None, *, dtype=None, casting="same_kind"):
418418
Examples
419419
--------
420420
>>> rng = np.random.default_rng()
421-
>>> arrays = [rng.standard_normal(size=(3,4)) for _ in range(10)]
421+
>>> arrays = [rng.normal(size=(3,4)) for _ in range(10)]
422422
>>> np.stack(arrays, axis=0).shape
423423
(10, 3, 4)
424424

numpy/lib/_function_base_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def flip(m, axis=None):
324324
[[1, 0],
325325
[3, 2]]])
326326
>>> rng = np.random.default_rng()
327-
>>> A = rng.standard_normal(size=(3,4,5))
327+
>>> A = rng.normal(size=(3,4,5))
328328
>>> np.all(np.flip(A,2) == A[:,:,::-1,...])
329329
True
330330
"""

numpy/lib/_histograms_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ def histogramdd(sample, bins=10, range=None, density=None, weights=None):
973973
Examples
974974
--------
975975
>>> rng = np.random.default_rng()
976-
>>> r = rng.standard_normal(size=(100,3))
976+
>>> r = rng.normal(size=(100,3))
977977
>>> H, edges = np.histogramdd(r, bins = (5, 8, 4))
978978
>>> H.shape, edges[0].size, edges[1].size, edges[2].size
979979
((5, 8, 4), 6, 9, 5)

numpy/lib/_twodim_base_impl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def fliplr(m):
9090
[3., 0., 0.]])
9191
9292
>>> rng = np.random.default_rng()
93-
>>> A = rng.standard_normal(size=(2,3,5))
93+
>>> A = rng.normal(size=(2,3,5))
9494
>>> np.all(np.fliplr(A) == A[:,::-1,...])
9595
True
9696
@@ -144,7 +144,7 @@ def flipud(m):
144144
[1., 0., 0.]])
145145
146146
>>> rng = np.random.default_rng()
147-
>>> A = rng.standard_normal(size=(2,3,5))
147+
>>> A = rng.normal(size=(2,3,5))
148148
>>> np.all(np.flipud(A) == A[::-1,...])
149149
True
150150

numpy/linalg/_linalg.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def tensorsolve(a, b, axes=None):
275275
>>> a = np.eye(2*3*4)
276276
>>> a.shape = (2*3, 4, 2, 3, 4)
277277
>>> rng = np.random.default_rng()
278-
>>> b = rng.standard_normal(size=(2*3, 4))
278+
>>> b = rng.normal(size=(2*3, 4))
279279
>>> x = np.linalg.tensorsolve(a, b)
280280
>>> x.shape
281281
(2, 3, 4)
@@ -458,7 +458,7 @@ def tensorinv(a, ind=2):
458458
>>> ainv.shape
459459
(8, 3, 4, 6)
460460
>>> rng = np.random.default_rng()
461-
>>> b = rng.standard_normal(size=(4, 6))
461+
>>> b = rng.normal(size=(4, 6))
462462
>>> np.allclose(np.tensordot(ainv, b), np.linalg.tensorsolve(a, b))
463463
True
464464
@@ -468,7 +468,7 @@ def tensorinv(a, ind=2):
468468
>>> ainv.shape
469469
(8, 3, 24)
470470
>>> rng = np.random.default_rng()
471-
>>> b = rng.standard_normal(24)
471+
>>> b = rng.normal(size=24)
472472
>>> np.allclose(np.tensordot(ainv, b, 1), np.linalg.tensorsolve(a, b))
473473
True
474474
@@ -982,7 +982,7 @@ def qr(a, mode='reduced'):
982982
Examples
983983
--------
984984
>>> rng = np.random.default_rng()
985-
>>> a = rng.standard_normal(size=(9, 6))
985+
>>> a = rng.normal(size=(9, 6))
986986
>>> Q, R = np.linalg.qr(a)
987987
>>> np.allclose(a, np.dot(Q, R)) # a does equal QR
988988
True
@@ -1708,12 +1708,9 @@ def svd(a, full_matrices=True, compute_uv=True, hermitian=False):
17081708
Examples
17091709
--------
17101710
>>> rng = np.random.default_rng()
1711-
>>> a_re = rng.standard_normal(size=(9, 6))
1712-
>>> a_im = rng.standard_normal(size=(9, 6))
1713-
>>> a = a_re + 1j*a_im
1714-
>>> b_re = rng.standard_normal(size=(2, 7, 8, 3))
1715-
>>> b_im = rng.standard_normal(size=(2, 7, 8, 3))
1716-
>>> b = b_re + 1j*b_im
1711+
>>> a = rng.normal(size=(9, 6)) + 1j*rng.normal(size=(9, 6))
1712+
>>> b = rng.normal(size=(2, 7, 8, 3)) + 1j*rng.normal(size=(2, 7, 8, 3))
1713+
17171714
17181715
Reconstruction based on full SVD, 2D case:
17191716
@@ -2191,7 +2188,7 @@ def pinv(a, rcond=None, hermitian=False, *, rtol=_NoValue):
21912188
``a+ * a * a+ == a+``:
21922189
21932190
>>> rng = np.random.default_rng()
2194-
>>> a = rng.standard_normal(size=(9, 6))
2191+
>>> a = rng.normal(size=(9, 6))
21952192
>>> B = np.linalg.pinv(a)
21962193
>>> np.allclose(a, np.dot(a, np.dot(B, a)))
21972194
True

numpy/polynomial/hermite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,10 +1461,10 @@ def hermfit(x, y, deg, rcond=None, full=False, w=None):
14611461
>>> from numpy.polynomial.hermite import hermfit, hermval
14621462
>>> x = np.linspace(-10, 10)
14631463
>>> rng = np.random.default_rng(seed=123)
1464-
>>> err = rng.standard_normal(size=(len(x)))/10
1464+
>>> err = rng.normal(scale=1./10,size=len(x))
14651465
>>> y = hermval(x, [1, 2, 3]) + err
14661466
>>> hermfit(x, y, 2)
1467-
array([1.02294967, 2.00016403, 2.99994614]) # may vary
1467+
array([1.02294967, 2.00016403, 2.99994614])
14681468
14691469
"""
14701470
return pu._fit(hermvander, x, y, deg, rcond, full, w)

numpy/polynomial/hermite_e.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,10 +1388,10 @@ def hermefit(x, y, deg, rcond=None, full=False, w=None):
13881388
>>> from numpy.polynomial.hermite_e import hermefit, hermeval
13891389
>>> x = np.linspace(-10, 10)
13901390
>>> rng = np.random.default_rng(seed=123)
1391-
>>> err = rng.standard_normal(size=(len(x)))/10
1391+
>>> err = rng.normal(scale=1./10,size=len(x))
13921392
>>> y = hermeval(x, [1, 2, 3]) + err
13931393
>>> hermefit(x, y, 2)
1394-
array([1.02284196, 2.00032805, 2.99978457]) # may vary
1394+
array([1.02284196, 2.00032805, 2.99978457])
13951395
13961396
"""
13971397
return pu._fit(hermevander, x, y, deg, rcond, full, w)

numpy/polynomial/laguerre.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,10 +1442,10 @@ def lagfit(x, y, deg, rcond=None, full=False, w=None):
14421442
>>> from numpy.polynomial.laguerre import lagfit, lagval
14431443
>>> x = np.linspace(0, 10)
14441444
>>> rng = np.random.default_rng(seed=123)
1445-
>>> err = rng.standard_normal(size=(len(x)))/10
1445+
>>> err = rng.normal(scale=1./10,size=len(x))
14461446
>>> y = lagval(x, [1, 2, 3]) + err
14471447
>>> lagfit(x, y, 2)
1448-
array([1.00578369, 1.99417356, 2.99827656]) # may vary
1448+
array([1.00578369, 1.99417356, 2.99827656])
14491449
14501450
"""
14511451
return pu._fit(lagvander, x, y, deg, rcond, full, w)

numpy/polynomial/polynomial.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,16 +1444,16 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None):
14441444
>>> from numpy.polynomial import polynomial as P
14451445
>>> x = np.linspace(-1,1,51) # x "data": [-1, -0.96, ..., 0.96, 1]
14461446
>>> rng = np.random.default_rng(seed=123)
1447-
>>> err = rng.standard_normal(size=len(x))
1447+
>>> err = rng.normal(size=len(x))
14481448
>>> y = x**3 - x + err # x^3 - x + Gaussian noise
14491449
>>> c, stats = P.polyfit(x,y,3,full=True)
14501450
>>> c # c[0], c[1] approx. -1, c[2] should be approx. 0, c[3] approx. 1
1451-
array([ 0.23111996, -1.02785049, -0.2241444 , 1.08405657]) # may vary
1451+
array([ 0.23111996, -1.02785049, -0.2241444 , 1.08405657])
14521452
>>> stats # note the large SSR, explaining the rather poor results
1453-
[array([48.312088]), # may vary
1454-
4, # may vary
1455-
array([1.38446749, 1.32119158, 0.50443316, 0.28853036]), # may vary
1456-
1.1324274851176597e-14] # may vary
1453+
[array([48.312088]),
1454+
4,
1455+
array([1.38446749, 1.32119158, 0.50443316, 0.28853036]),
1456+
1.1324274851176597e-14]
14571457
14581458
Same thing without the added noise
14591459
@@ -1462,10 +1462,10 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None):
14621462
>>> c # c[0], c[1] ~= -1, c[2] should be "very close to 0", c[3] ~= 1
14631463
array([-6.73496154e-17, -1.00000000e+00, 0.00000000e+00, 1.00000000e+00])
14641464
>>> stats # note the minuscule SSR
1465-
[array([8.79579319e-31]), # may vary
1466-
4, # may vary
1467-
array([1.38446749, 1.32119158, 0.50443316, 0.28853036]), # may vary
1468-
1.1324274851176597e-14] # may vary
1465+
[array([8.79579319e-31]),
1466+
4,
1467+
array([1.38446749, 1.32119158, 0.50443316, 0.28853036]),
1468+
1.1324274851176597e-14]
14691469
14701470
"""
14711471
return pu._fit(polyvander, x, y, deg, rcond, full, w)

0 commit comments

Comments
 (0)