🌐
W3Schools
w3schools.com › python › numpy › numpy_data_types.asp
NumPy Data Types
We use the array() function to create arrays, this function can take an optional argument: dtype that allows us to define the expected data type of the array elements: ... import numpy as np arr = np.array([1, 2, 3, 4], dtype='S') print(arr) ...
🌐
NumPy
numpy.org › doc › stable › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.5 Manual
Such conversions are done by the dtype constructor: What can be converted to a data-type object is described below: ... Used as-is. ... The default data type: float64. ... The 24 built-in array scalar type objects all convert to an associated data-type object.
🌐
Python Course
python-course.eu › numerical-programming › numpy-data-objects-dtype.php
3. Numpy Data Objects, dtype | Numerical Programming
Before we work with a complex data structure like the one shown above, let’s first introduce dtype using a very simple example. We define a data type based on int16 and refer to it as i16. (Admittedly, this isn’t a very descriptive name, but we’ll use it just for this example.) The elements of a list named lst are then converted to the i16 type to create a two-dimensional array called A. import numpy as np i16 = np.dtype(np.int16) print(i16) lst = [ [3.4, 8.7, 9.9], [1.1, -7.8, -0.7], [4.1, 12.3, 4.8] ] A = np.array(lst, dtype=i16) print(A)
🌐
Cach3
w3schools.com.cach3.com › python › numpy_data_types.asp.html
NumPy Data Types - W3Schools
We use the array() function to create arrays, this function can take an optional argument: dtype that allows us to define the expected data type of the array elements: ... import numpy as np arr = np.array([1, 2, 3, 4], dtype='S') print(arr) print(arr.dtype) Try it Yourself »
🌐
NumPy
numpy.org › doc › 2.1 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.1 Manual
The generated data-type fields are named 'f0', 'f1', …, 'f<N-1>' where N (>1) is the number of comma-separated basic formats in the string. If the optional shape specifier is provided, then the data-type for the corresponding field describes a sub-array. ... >>> dt = np.dtype('uint32') # ...
🌐
NumPy
numpy.org › doc › 2.3 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.3 Manual
Such conversions are done by the dtype constructor: What can be converted to a data-type object is described below: ... Used as-is. ... The default data type: float64. ... The 24 built-in array scalar type objects all convert to an associated data-type object.
🌐
DataCamp
datacamp.com › doc › numpy › data-types
NumPy Data Types
In this syntax, `dtype=np.int32` specifies that the array elements should be stored as 32-bit integers. python import numpy as np array = np.array([1, 2, 3], dtype=np.int32) print(array.dtype)
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_data_types.htm
NumPy - Data Types
Original array: [1.1 2.2 3.3 4.4 5.5] Original dtype: float64 Converted array: [1 2 3 4 5] Converted dtype: int32 · You can also specify the data type during array creation to avoid the need to convert the type later. Now, we are creating an array of integers by specifying the float data type using the numpy.float32() function −
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.dtype.html
numpy.ndarray.dtype — NumPy v2.2 Manual
Setting will replace the dtype without modifying the memory (see also ndarray.view and ndarray.astype). ... Cast the values contained in the array to a new data-type.
🌐
W3Schools
w3schools.com › python › numpy › trypython.asp
W3Schools online PYTHON editor
The W3Schools online code editor allows you to edit code and view the result in your browser
Find elsewhere
🌐
Imperial College London
python.pages.doc.ic.ac.uk › 2022 › lessons › numpy › 02-ndarray › 04-dtype.html
Introduction to NumPy and Matplotlib > np.dtype | Python Programming (70053 Autumn Term 2022/2023) | Department of Computing | Imperial College London
This can either be standard Python types (e.g. int or float) or a np.dtype (e.g. np.int32, np.float64) >>> x = np.array([0, 1, 2, 3], dtype=float) >>> print(x.dtype) float64 >>> x = np.array([0, 1, 2, 3], dtype=np.int32) >>> print(x.dtype) int32 >>> x = np.array([0, 1, 2, 3], dtype=np.uint32) >>> print(x.dtype) uint32 >>> x = np.array([0, 1, 2, 3], dtype=np.float64) >>> print(x.dtype) float64 uint32 is an unsigned integer (non-negative integer).
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.dtype.html
numpy.ndarray.dtype — NumPy v2.5 Manual
January 31, 2021 - >>> import numpy as np >>> x = np.arange(4).reshape((2, 2)) >>> x array([[0, 1], [2, 3]]) >>> x.dtype dtype('int64') # may vary (OS, bitness) >>> isinstance(x.dtype, np.dtype) True
🌐
NumPy
numpy.org › doc › 2.2 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.2 Manual
The generated data-type fields are named 'f0', 'f1', …, 'f<N-1>' where N (>1) is the number of comma-separated basic formats in the string. If the optional shape specifier is provided, then the data-type for the corresponding field describes a sub-array. ... >>> dt = np.dtype('uint32') # ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › data-type-object-dtype-numpy-python
Data type Object (dtype) in NumPy Python - GeeksforGeeks
May 20, 2026 - Explanation: attribute arr.dtype returns the data type of the array elements, which is int in this case because all values are integers. A dtype object is an instance of the numpy.dtype class.
🌐
NumPy
numpy.org › doc › 2.1 › user › basics.types.html
Data types — NumPy v2.1 Manual
Some dtypes have trailing underscore ... a set of fixed-size aliases are provided (See Sized aliases). NumPy generally returns elements of arrays as array scalars (a scalar with an associated dtype)....
Top answer
1 of 1
4

A python list can contain disparately typed objects, e.g. X = ['apples', 'oranges',10]. If you do type([10]) you'll see the Python type for the container is technically called a list, not an array.

In contrast, in a numpy array all objects are of the same type, the dtype.

The docs are telling you that on creation of a numpy array, the dtype is set to the type that will hold all of the existing objects.

See, look:

the type will be determined as the minimum type required to hold the objects in the sequence

The writers perhaps should have added "and not their values"

We can make a uint8 ten easily enough:

ten = np.uint8(10)

If that is put into a Python list, it retains its type because Python lists preserve types. If that list is sent to numpy.array() to make a numpy array, then the numpy array will use dtype np.uint8 because it is big enough to hold all (1) of the pre-existing Python list objects.

In [49]: np.array([ten]).dtype
Out[49]: dtype('uint8')

But if we use a literal 10, python will create an int object for it instead of an np.uint8 because np.uint8 is peculiar to numpy and all 10 does is invoke python to create that number.

If we make a Python list containing a literal 10, we duplicate your result (with machine-architecture ints):

In [50]: np.array([10]).dtype
Out[50]: dtype('int64')

And if we put the two types together in a python list, and send that list to np.array for creation of a numpy array, then the dtype must be big enough to hold both objects, in this case int64.

In [51]: np.array([ten, 10]).dtype
Out[51]: dtype('int64')
🌐
NumPy
numpy.org › devdocs › user › basics.types.html
Data types — NumPy v2.6.dev0 Manual
Some dtypes have trailing underscore ... a set of fixed-size aliases are provided (See Sized aliases). NumPy generally returns elements of arrays as array scalars (a scalar with an associated dtype)....
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.dtype.html
numpy.ndarray.dtype — NumPy v2.1 Manual
Setting will replace the dtype without modifying the memory (see also ndarray.view and ndarray.astype). ... Cast the values contained in the array to a new data-type.
🌐
Python for Data Science
python4data.science › en › latest › workspace › numpy › dtype.html
dtype - Python for Data Science
May 15, 2026 - ndarray is a container for homogeneous data, i.e. all elements must be of the same type. Each array has a dtype, an object that describes the data type of the array: [1]: import numpy as np rng = np.random.default_rng() data = rng.random((7, ...
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: astype() to change dtype of an array | note.nkmk.me
February 4, 2024 - NumPy arrays (ndarray) cannot be specified. You need to specify either the data type of the array or provide a specific value instead. a = np.array([1, 2, 3], dtype=np.int8) print(type(a)) # <class 'numpy.ndarray'> # print(np.iinfo(a)) # ValueError: Invalid integer data type 'O'. print(np.iinfo(a.dtype)) # Machine parameters for int8 # --------------------------------------------------------------- # min = -128 # max = 127 # --------------------------------------------------------------- # print(np.iinfo(a[0])) # Machine parameters for int8 # --------------------------------------------------------------- # min = -128 # max = 127 # --------------------------------------------------------------- #