@@ -144,8 +144,7 @@ rows. All off-diagonal values change places. Let's see how long NumPy's
144144transpose function takes, by transposing a huge (10 000 ✕ 20 000) matrix::
145145
146146 import numpy as np
147- rng = np.random.default_rng(seed=0)
148- a = rng.rand(10_000, 20_000)
147+ a = np.random.rand(10_000, 20_000)
149148 print(f'Matrix `a` takes up {a.nbytes / 10**6} MB')
150149
151150Let's time the :func: `numpy.transpose ` function::
@@ -230,8 +229,7 @@ copying any data by just modifying the ``.strides`` of the array::
230229
231230 import numpy as np
232231
233- rng = np.random.default_rng(seed=0)
234- a = rng.rand(10_000, 20_000)
232+ a = np.random.rand(10_000, 20_000)
235233 b = a.transpose()
236234
237235 print(a.strides) # (160000, 8)
@@ -242,8 +240,7 @@ Another example: reshaping
242240Modifying the shape of an array through :func: `numpy.reshape ` is also
243241accomplished without any copying of data by modifying the ``.strides ``::
244242
245- rng = np.random.default_rng(seed=0)
246- a = rng.rand(20_000, 10_000)
243+ a = np.random.rand(20_000, 10_000)
247244 print(f'{a.strides=}') # (80000, 8)
248245 b = a.reshape(40_000, 5_000)
249246 print(f'{b.strides=}') # (40000, 8)
@@ -309,8 +306,7 @@ If :func:`numpy.transpose` is fast, and :func:`numpy.reshape` is fast, then
309306doing them both must be fast too, right?::
310307
311308 # Create a large array
312- rng = np.random.default_rng(seed=0)
313- a = rng.rand(10_000, 20_000)
309+ a = np.random.rand(10_000, 20_000)
314310
315311Measuring the time it takes to first transpose and then reshape::
316312
0 commit comments