Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions advanced/advanced_numpy/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ Casting
>>> y + 1
array([2, 3, 4, 5], dtype=int8)
>>> y + 256
array([257, 258, 259, 260], dtype=int16)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: Python integer 256 out of bounds for int8
>>> y + 256.0
array([257., 258., 259., 260.])
>>> y + np.array([256], dtype=np.int32)
Expand Down Expand Up @@ -507,9 +509,9 @@ Main point
(3, 1)
>>> byte_offset = 3 * 1 + 1 * 2 # to find x[1, 2]
>>> x.flat[byte_offset]
6
np.int8(6)
>>> x[1, 2]
6
np.int8(6)

simple, **flexible**

Expand Down Expand Up @@ -1343,18 +1345,12 @@ Array siblings: :class:`chararray`, :class:`maskedarray`
:class:`chararray`: vectorized string operations
--------------------------------------------------

>>> x = np.array(['a', ' bbb', ' ccc']).view(np.chararray)
>>> x.lstrip(' ')
chararray(['a', 'bbb', 'ccc'],
dtype='...')
>>> x = np.char.asarray(['a', ' bbb', ' ccc'])
>>> x
chararray(['a', ' bbb', ' ccc'], dtype='<U5')
>>> x.upper()
chararray(['A', ' BBB', ' CCC'],
dtype='...')
chararray(['A', ' BBB', ' CCC'], dtype='<U5')

.. note::

``.view()`` has a second meaning: it can make an ndarray an instance
of a specialized ndarray subclass

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

>>> mx.mean()
2.75
np.float64(2.75)
>>> np.mean(mx)
2.75
np.float64(2.75)

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

>>> print(np.__version__)
1...
2...

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

Expand Down
12 changes: 6 additions & 6 deletions advanced/image_processing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Increase contrast by setting min and max values::
<matplotlib.image.AxesImage object at 0x...>
>>> # Remove axes and ticks
>>> plt.axis('off')
(-0.5, 1023.5, 767.5, -0.5)
(np.float64(-0.5), np.float64(1023.5), np.float64(767.5), np.float64(-0.5))

Draw contour lines::

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

>>> face = sp.datasets.face(gray=True)
>>> face[0, 40]
127
np.uint8(127)
>>> # Slicing
>>> face[10:13, 20:23]
array([[141, 153, 145],
Expand Down Expand Up @@ -222,9 +222,9 @@ Statistical information

>>> face = sp.datasets.face(gray=True)
>>> face.mean()
113.48026784261067
np.float64(113.48026784261067)
>>> face.max(), face.min()
(250, 0)
(np.uint8(250), np.uint8(0))


``np.histogram``
Expand Down Expand Up @@ -653,9 +653,9 @@ Use mathematical morphology to clean up the result::
>>> eroded_tmp = sp.ndimage.binary_erosion(tmp)
>>> reconstruct_final = np.logical_not(sp.ndimage.binary_propagation(eroded_tmp, mask=tmp))
>>> np.abs(mask - close_img).mean()
0.00640699...
np.float64(0.00640699...)
>>> np.abs(mask - reconstruct_final).mean()
0.00082232...
np.float64(0.00082232...)

.. topic:: **Exercise**
:class: green
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def store(X):
extent=[x_min, x_max, y_min, y_max],
cmap=plt.cm.gray_r,
origin="lower",
vmax=log_z.min() + 1.5 * log_z.ptp(),
vmax=log_z.min() + 1.5 * np.ptp(log_z),
)
contours = plt.contour(
log_z,
Expand Down
8 changes: 4 additions & 4 deletions advanced/mathematical_optimization/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ Brent's method to find the minimum of a function:
True
>>> x_min = result.x
>>> x_min
0.50...
np.float64(0.50...)
>>> x_min - 0.5
5.8...e-09
np.float64(5.8...e-09)


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

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

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

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

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

Expand Down
18 changes: 9 additions & 9 deletions advanced/scipy_sparse/dia_array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ Examples
>>> mtx.offsets
array([ 0, -1, 2], dtype=int32)
>>> print(mtx)
(0, 0) 1
(1, 1) 2
(2, 2) 3
(3, 3) 4
(1, 0) 5
(2, 1) 6
(3, 2) 7
(0, 2) 11
(1, 3) 12
(np.int32(0), np.int32(0)) 1
(np.int32(1), np.int32(1)) 2
(np.int32(2), np.int32(2)) 3
(np.int32(3), np.int32(3)) 4
(np.int32(1), np.int32(0)) 5
(np.int32(2), np.int32(1)) 6
(np.int32(3), np.int32(2)) 7
(np.int32(0), np.int32(2)) 11
(np.int32(1), np.int32(3)) 12
>>> mtx.toarray()
array([[ 1, 0, 11, 0],
[ 5, 2, 0, 12],
Expand Down
2 changes: 1 addition & 1 deletion advanced/scipy_sparse/dok_array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Examples
* slicing and indexing::

>>> mtx[1, 1]
0.0
np.float64(0.0)
>>> mtx[[1], 1:3]
<1x2 sparse array of type '<... 'numpy.float64'>'
with 1 stored elements in Dictionary Of Keys format>
Expand Down
9 changes: 0 additions & 9 deletions intro/help/help.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ just to display help and docstrings...
learning by example. More standard documentation is also available.


Finally, two more "technical" possibilities are useful as well:

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

* numpy.lookfor looks for keywords inside the docstrings of specified modules.

.. ipython::
:okwarning:

In [45]: np.lookfor('convolution')

* If everything listed above fails (and Google doesn't have the
answer)... don't despair! There is a vibrant Scientific Python community.
Scientific Python is present on various platform.
Expand Down
4 changes: 2 additions & 2 deletions intro/numpy/advanced_operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ For example, :math:`3x^2 + 2x - 1`::

>>> p = np.poly1d([3, 2, -1])
>>> p(0)
-1
np.int64(-1)
>>> p.roots
array([-1. , 0.33333333])
>>> p.order
Expand Down Expand Up @@ -60,7 +60,7 @@ e.g. the Chebyshev basis.

>>> p = np.polynomial.Polynomial([-1, 2, 3]) # coefs in different order!
>>> p(0)
-1.0
np.float64(-1.0)
>>> p.roots()
array([-1. , 0.33333333])
>>> p.degree() # In general polynomials do not always expose 'order'
Expand Down
14 changes: 2 additions & 12 deletions intro/numpy/array_object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@ NumPy Reference documentation

- Looking for something:

.. sourcecode:: pycon

>>> np.lookfor('create array') # doctest: +SKIP
Search results for 'create array'
---------------------------------
numpy.array
Create an array.
numpy.memmap
Create a memory-map to an array stored in a *binary* file on disk.

.. ipython::

In [6]: np.con*?
Expand Down Expand Up @@ -463,7 +453,7 @@ other Python sequences (e.g. lists):
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> a[0], a[2], a[-1]
(0, 2, 9)
(np.int64(0), np.int64(2), np.int64(9))

.. warning::

Expand All @@ -487,7 +477,7 @@ For multidimensional arrays, indices are tuples of integers:
[0, 1, 0],
[0, 0, 2]])
>>> a[1, 1]
1
np.int64(1)
>>> a[2, 1] = 10 # third line, second column
>>> a
array([[ 0, 0, 0],
Expand Down
12 changes: 6 additions & 6 deletions intro/numpy/elaborate_arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ Floating-point numbers:
::

>>> np.finfo(np.float32).eps
1.1920929e-07
np.float32(1.1920929e-07)
>>> np.finfo(np.float64).eps
2.2204460492503131e-16
np.float64(2.220446049250313e-16)

>>> np.float32(1e-8) + np.float32(1) == 1
True
np.True_
>>> np.float64(1e-8) + np.float64(1) == 1
False
np.False_

Complex floating-point numbers:

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

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

Multiple fields at once::

Expand Down
Loading