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
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') # ...
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)....
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.
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 # --------------------------------------------------------------- #