Skip to content

Commit

Permalink
DOC: respond to review comments
Browse files Browse the repository at this point in the history
[skip actions] [skip azp] [skip cirrus]
  • Loading branch information
ngoldbaum committed Dec 28, 2023
1 parent 1c0b2c4 commit 3c1c498
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions doc/source/user/basics.types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,34 @@ numpy as np`` the dtypes are available as e.g. `numpy.bool`,
`numpy.float32`, etc.

Data-types can be used as functions to convert python numbers to array scalars
(see the array scalar section for an explanation), python sequences of numbers
to arrays of that type, or as arguments to the dtype keyword that many numpy
functions or methods accept. Some examples::
(see the array scalar section for an explanation) or as arguments to the dtype
keyword that many numpy functions or methods accept. Some examples::

>>> x = np.float32(1.0)
>>> x
1.0
>>> y = np.int_([1,2,4])
>>> y
array([1, 2, 4])
>>> z = np.arange(3, dtype=np.uint8)
>>> z
array([0, 1, 2], dtype=uint8)

Array types can also be referred to by character codes, mostly to retain
backward compatibility with older packages such as Numeric, but also for
defining :ref:`structured data types <structured_arrays>`. Some
documentation may refer to these character codes, for example::
Array types can also be referred to by character codes, for example::

>>> np.array([1, 2, 3], dtype='f')
array([1., 2., 3.], dtype=float32)
>>> np.array([1, 2, 3], dtype='d')
array([1., 2., 3.], dtype=float64)

We recommend using dtype objects instead.
See :ref:`arrays.dtypes.constructing` for more information about specifying and
constructing data type objects.

To convert the type of an array, use the .astype() method (preferred) or
the type itself as a function. For example: ::

>>> z.astype(float) #doctest: +NORMALIZE_WHITESPACE
>>> z.astype(np.float64) #doctest: +NORMALIZE_WHITESPACE
array([0., 1., 2.])
>>> np.int8(z)
array([0, 1, 2], dtype=int8)

Note that, above, we use the *Python* float object as a dtype. NumPy knows that
Note that, above, we could have used the *Python* float object as a dtype
instead of `numpy.float64`. NumPy knows that
:class:`int` refers to `numpy.int_`, :class:`bool` means
`numpy.bool`, that :class:`float` is `numpy.float64` and
:class:`complex` is `numpy.complex128`. The other data-types do not have
Expand All @@ -65,9 +60,9 @@ dtype objects also contain information about the type, such as its bit-width
and its byte-order. The data type can also be used indirectly to query
properties of the type, such as whether it is an integer::

>>> d = np.dtype(int)
>>> d #doctest: +SKIP
dtype('int32')
>>> d = np.dtype(int64)
>>> d
dtype('int64')

>>> np.issubdtype(d, np.integer)
True
Expand All @@ -93,9 +88,9 @@ Data Types for Strings and Bytes
--------------------------------

In addition to numerical types, NumPy also supports storing unicode strings, via
`numpy.dtypes.StrDType` (``U`` character code), null-terminated byte sequences via
`numpy.dtypes.BytesDType` (``S`` character code), and arbitrary byte sequences, via
`numpy.dtypes.VoidDType` (``V`` character code).
the `numpy.str_` dtype (``U`` character code), null-terminated byte sequences via
`numpy.bytes_` (``S`` character code), and arbitrary byte sequences, via
`numpy.void` (``V`` character code).

The ``StrDType``, ``BytesDType``, and ``VoidDType`` are *fixed-width* data
types. They are parameterized by a width, in either bytes or unicode points,
Expand Down

0 comments on commit 3c1c498

Please sign in to comment.