Skip to content

Commit a1da5b5

Browse files
Merge pull request #767 from jarrodmillman/np2
Update numpy version (2.0)
2 parents b12cc1c + 4da5c27 commit a1da5b5

File tree

18 files changed

+103
-126
lines changed

18 files changed

+103
-126
lines changed

advanced/advanced_numpy/index.rst

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ Casting
312312
>>> y + 1
313313
array([2, 3, 4, 5], dtype=int8)
314314
>>> y + 256
315-
array([257, 258, 259, 260], dtype=int16)
315+
Traceback (most recent call last):
316+
File "<stdin>", line 1, in <module>
317+
OverflowError: Python integer 256 out of bounds for int8
316318
>>> y + 256.0
317319
array([257., 258., 259., 260.])
318320
>>> y + np.array([256], dtype=np.int32)
@@ -507,9 +509,9 @@ Main point
507509
(3, 1)
508510
>>> byte_offset = 3 * 1 + 1 * 2 # to find x[1, 2]
509511
>>> x.flat[byte_offset]
510-
6
512+
np.int8(6)
511513
>>> x[1, 2]
512-
6
514+
np.int8(6)
513515
514516
simple, **flexible**
515517

@@ -1343,18 +1345,12 @@ Array siblings: :class:`chararray`, :class:`maskedarray`
13431345
:class:`chararray`: vectorized string operations
13441346
--------------------------------------------------
13451347

1346-
>>> x = np.array(['a', ' bbb', ' ccc']).view(np.chararray)
1347-
>>> x.lstrip(' ')
1348-
chararray(['a', 'bbb', 'ccc'],
1349-
dtype='...')
1348+
>>> x = np.char.asarray(['a', ' bbb', ' ccc'])
1349+
>>> x
1350+
chararray(['a', ' bbb', ' ccc'], dtype='<U5')
13501351
>>> x.upper()
1351-
chararray(['A', ' BBB', ' CCC'],
1352-
dtype='...')
1352+
chararray(['A', ' BBB', ' CCC'], dtype='<U5')
13531353

1354-
.. note::
1355-
1356-
``.view()`` has a second meaning: it can make an ndarray an instance
1357-
of a specialized ndarray subclass
13581354

13591355
:class:`masked_array` missing data
13601356
------------------------------------
@@ -1376,9 +1372,9 @@ One way to describe this is to create a masked array::
13761372
Masked mean ignores masked data::
13771373

13781374
>>> mx.mean()
1379-
2.75
1375+
np.float64(2.75)
13801376
>>> np.mean(mx)
1381-
2.75
1377+
np.float64(2.75)
13821378

13831379
.. warning:: Not all NumPy functions respect masks, for instance
13841380
``np.dot``, so check the return types.
@@ -1588,7 +1584,7 @@ Good bug report
15881584
3. Version of NumPy/SciPy
15891585

15901586
>>> print(np.__version__)
1591-
1...
1587+
2...
15921588

15931589
**Check that the following is what you expect**
15941590

advanced/image_processing/index.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Increase contrast by setting min and max values::
137137
<matplotlib.image.AxesImage object at 0x...>
138138
>>> # Remove axes and ticks
139139
>>> plt.axis('off')
140-
(-0.5, 1023.5, 767.5, -0.5)
140+
(np.float64(-0.5), np.float64(1023.5), np.float64(767.5), np.float64(-0.5))
141141

142142
Draw contour lines::
143143

@@ -190,7 +190,7 @@ Images are arrays: use the whole ``numpy`` machinery.
190190

191191
>>> face = sp.datasets.face(gray=True)
192192
>>> face[0, 40]
193-
127
193+
np.uint8(127)
194194
>>> # Slicing
195195
>>> face[10:13, 20:23]
196196
array([[141, 153, 145],
@@ -222,9 +222,9 @@ Statistical information
222222

223223
>>> face = sp.datasets.face(gray=True)
224224
>>> face.mean()
225-
113.48026784261067
225+
np.float64(113.48026784261067)
226226
>>> face.max(), face.min()
227-
(250, 0)
227+
(np.uint8(250), np.uint8(0))
228228

229229

230230
``np.histogram``
@@ -653,9 +653,9 @@ Use mathematical morphology to clean up the result::
653653
>>> eroded_tmp = sp.ndimage.binary_erosion(tmp)
654654
>>> reconstruct_final = np.logical_not(sp.ndimage.binary_propagation(eroded_tmp, mask=tmp))
655655
>>> np.abs(mask - close_img).mean()
656-
0.00640699...
656+
np.float64(0.00640699...)
657657
>>> np.abs(mask - reconstruct_final).mean()
658-
0.00082232...
658+
np.float64(0.00082232...)
659659

660660
.. topic:: **Exercise**
661661
:class: green

advanced/mathematical_optimization/examples/plot_gradient_descent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def store(X):
242242
extent=[x_min, x_max, y_min, y_max],
243243
cmap=plt.cm.gray_r,
244244
origin="lower",
245-
vmax=log_z.min() + 1.5 * log_z.ptp(),
245+
vmax=log_z.min() + 1.5 * np.ptp(log_z),
246246
)
247247
contours = plt.contour(
248248
log_z,

advanced/mathematical_optimization/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ Brent's method to find the minimum of a function:
180180
True
181181
>>> x_min = result.x
182182
>>> x_min
183-
0.50...
183+
np.float64(0.50...)
184184
>>> x_min - 0.5
185-
5.8...e-09
185+
np.float64(5.8...e-09)
186186

187187

188188
.. |1d_optim_1| image:: auto_examples/images/sphx_glr_plot_1d_optim_001.png
@@ -824,7 +824,7 @@ handy.
824824
given, and a gradient computed numerically:
825825

826826
>>> sp.optimize.check_grad(f, jacobian, [2, -1])
827-
2.384185791015625e-07
827+
np.float64(2.384185791015625e-07)
828828

829829
See also :func:`scipy.optimize.approx_fprime` to find your errors.
830830

@@ -897,7 +897,7 @@ if we compute the norm ourselves and use a good generic optimizer
897897
... return np.sum(f(x)**2)
898898
>>> result = sp.optimize.minimize(g, x0, method="BFGS")
899899
>>> result.fun
900-
2.6940...e-11
900+
np.float64(2.6940...e-11)
901901

902902
BFGS needs more function calls, and gives a less precise result.
903903

advanced/scipy_sparse/dia_array.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ Examples
6363
>>> mtx.offsets
6464
array([ 0, -1, 2], dtype=int32)
6565
>>> print(mtx)
66-
(0, 0) 1
67-
(1, 1) 2
68-
(2, 2) 3
69-
(3, 3) 4
70-
(1, 0) 5
71-
(2, 1) 6
72-
(3, 2) 7
73-
(0, 2) 11
74-
(1, 3) 12
66+
(np.int32(0), np.int32(0)) 1
67+
(np.int32(1), np.int32(1)) 2
68+
(np.int32(2), np.int32(2)) 3
69+
(np.int32(3), np.int32(3)) 4
70+
(np.int32(1), np.int32(0)) 5
71+
(np.int32(2), np.int32(1)) 6
72+
(np.int32(3), np.int32(2)) 7
73+
(np.int32(0), np.int32(2)) 11
74+
(np.int32(1), np.int32(3)) 12
7575
>>> mtx.toarray()
7676
array([[ 1, 0, 11, 0],
7777
[ 5, 2, 0, 12],

advanced/scipy_sparse/dok_array.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Examples
4646
* slicing and indexing::
4747

4848
>>> mtx[1, 1]
49-
0.0
49+
np.float64(0.0)
5050
>>> mtx[[1], 1:3]
5151
<1x2 sparse array of type '<... 'numpy.float64'>'
5252
with 1 stored elements in Dictionary Of Keys format>

intro/help/help.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ just to display help and docstrings...
5151
learning by example. More standard documentation is also available.
5252

5353

54-
Finally, two more "technical" possibilities are useful as well:
55-
5654
* In Ipython, the magical function ``%psearch`` search for objects
5755
matching patterns. This is useful if, for example, one does not know
5856
the exact name of a function.
@@ -63,13 +61,6 @@ Finally, two more "technical" possibilities are useful as well:
6361
In [3]: import numpy as np
6462
In [4]: %psearch np.diag*
6563

66-
* numpy.lookfor looks for keywords inside the docstrings of specified modules.
67-
68-
.. ipython::
69-
:okwarning:
70-
71-
In [45]: np.lookfor('convolution')
72-
7364
* If everything listed above fails (and Google doesn't have the
7465
answer)... don't despair! There is a vibrant Scientific Python community.
7566
Scientific Python is present on various platform.

intro/numpy/advanced_operations.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ For example, :math:`3x^2 + 2x - 1`::
2525

2626
>>> p = np.poly1d([3, 2, -1])
2727
>>> p(0)
28-
-1
28+
np.int64(-1)
2929
>>> p.roots
3030
array([-1. , 0.33333333])
3131
>>> p.order
@@ -60,7 +60,7 @@ e.g. the Chebyshev basis.
6060

6161
>>> p = np.polynomial.Polynomial([-1, 2, 3]) # coefs in different order!
6262
>>> p(0)
63-
-1.0
63+
np.float64(-1.0)
6464
>>> p.roots()
6565
array([-1. , 0.33333333])
6666
>>> p.degree() # In general polynomials do not always expose 'order'

intro/numpy/array_object.rst

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,6 @@ NumPy Reference documentation
113113
114114
- Looking for something:
115115

116-
.. sourcecode:: pycon
117-
118-
>>> np.lookfor('create array') # doctest: +SKIP
119-
Search results for 'create array'
120-
---------------------------------
121-
numpy.array
122-
Create an array.
123-
numpy.memmap
124-
Create a memory-map to an array stored in a *binary* file on disk.
125-
126116
.. ipython::
127117

128118
In [6]: np.con*?
@@ -463,7 +453,7 @@ other Python sequences (e.g. lists):
463453
>>> a
464454
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
465455
>>> a[0], a[2], a[-1]
466-
(0, 2, 9)
456+
(np.int64(0), np.int64(2), np.int64(9))
467457

468458
.. warning::
469459

@@ -487,7 +477,7 @@ For multidimensional arrays, indices are tuples of integers:
487477
[0, 1, 0],
488478
[0, 0, 2]])
489479
>>> a[1, 1]
490-
1
480+
np.int64(1)
491481
>>> a[2, 1] = 10 # third line, second column
492482
>>> a
493483
array([[ 0, 0, 0],

intro/numpy/elaborate_arrays.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ Floating-point numbers:
9797
::
9898

9999
>>> np.finfo(np.float32).eps
100-
1.1920929e-07
100+
np.float32(1.1920929e-07)
101101
>>> np.finfo(np.float64).eps
102-
2.2204460492503131e-16
102+
np.float64(2.220446049250313e-16)
103103

104104
>>> np.float32(1e-8) + np.float32(1) == 1
105-
True
105+
np.True_
106106
>>> np.float64(1e-8) + np.float64(1) == 1
107-
False
107+
np.False_
108108

109109
Complex floating-point numbers:
110110

@@ -173,11 +173,11 @@ Field access works by indexing with field names::
173173
>>> samples['value']
174174
array([0.37, 0.11, 0.13, 0.37, 0.11, 0.13])
175175
>>> samples[0]
176-
(b'ALFA', 1., 0.37)
176+
np.void((b'ALFA', 1.0, 0.37), dtype=[('sensor_code', 'S4'), ('position', '<f8'), ('value', '<f8')])
177177

178178
>>> samples[0]['sensor_code'] = 'TAU'
179179
>>> samples[0]
180-
(b'TAU', 1., 0.37)
180+
np.void((b'TAU', 1.0, 0.37), dtype=[('sensor_code', 'S4'), ('position', '<f8'), ('value', '<f8')])
181181

182182
Multiple fields at once::
183183

0 commit comments

Comments
 (0)