The following code might help:
import numpy as np
dt = np.dtype([('name1', '|S10'), ('name2', '<f8')])
tuplelist=[
('n1', 1.2),
('n2', 3.4),
]
arr = np.array(tuplelist, dtype=dt)
print(arr['name1'])
# ['n1' 'n2']
print(arr['name2'])
# [ 1.2 3.4]
Your immediate problem was that np.dtype expects the format specifiers to be numpy types, such as '|S10' or '<f8' and not Python types, such as str or float. If you type help(np.dtype) you'll see many examples of how np.dtypes can be specified. (I've only mentioned a few.)
Note that np.array expects a list of tuples. It's rather particular about that.
A list of lists raises TypeError: expected a readable buffer object.
A (tuple of tuples) or a (tuple of lists) raises ValueError: setting an array element with a sequence.
NumPy
numpy.org › doc › stable › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.4 Manual
The offsets value is a list of byte offsets (limited to ctypes.c_int) for each field, while the titles value is a list of titles for each field (None can be used if no title is desired for that field). The titles can be any object, but when a str object will add another entry to the fields dictionary keyed by the title and referencing the same field tuple which will contain the title as an additional tuple member. The itemsize key allows the total size of the dtype to be set, and must be an integer large enough so all the fields are within the dtype.
W3Schools
w3schools.com › python › numpy › numpy_data_types.asp
NumPy Data Types
Below is a list of all data types ... other type ( void ) The NumPy array object has a property called dtype that returns the data type of the array: Get the data type of an array object: import numpy as np arr = np.array([1, 2, ...
Videos
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.4 Manual
NumPy generally returns elements of arrays as array scalars (a scalar with an associated dtype). Array scalars differ from Python scalars, but for the most part they can be used interchangeably (the primary exception is for versions of Python older than v2.x, where integer array scalars cannot act as indices for lists ...
NumPy
numpy.org › doc › 2.1 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.1 Manual
The offsets value is a list of byte offsets (limited to ctypes.c_int) for each field, while the titles value is a list of titles for each field (None can be used if no title is desired for that field). The titles can be any object, but when a str object will add another entry to the fields dictionary keyed by the title and referencing the same field tuple which will contain the title as an additional tuple member. The itemsize key allows the total size of the dtype to be set, and must be an integer large enough so all the fields are within the dtype.
NumPy
numpy.org › doc › stable › reference › generated › numpy.dtype.names.html
numpy.dtype.names — NumPy v1.26 Manual
January 31, 2021 - dtype.names# Ordered list of field names, or None if there are no fields. The names are ordered according to increasing byte offset. This can be used, for example, to walk through all of the named fields in offset order. Examples · Try it in your browser! >>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))]) >>> dt.names ('name', 'grades') Go BackOpen In Tab ·
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)
NumPy
numpy.org › doc › stable › reference › generated › numpy.dtype.html
numpy.dtype — NumPy v2.4 Manual
Boolean indicating whether the byte order of this dtype is native to the platform. ... The element size of this data-type object. ... A character code (one of ‘biufcmMOSTUV’) identifying the general kind of data. ... Either None or a readonly dictionary of metadata (mappingproxy). ... A bit-width name for this data-type. ... Ordered list ...
NumPy
numpy.org › devdocs › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.6.dev0 Manual
The offsets value is a list of byte offsets (limited to ctypes.c_int) for each field, while the titles value is a list of titles for each field (None can be used if no title is desired for that field). The titles can be any object, but when a str object will add another entry to the fields dictionary keyed by the title and referencing the same field tuple which will contain the title as an additional tuple member. The itemsize key allows the total size of the dtype to be set, and must be an integer large enough so all the fields are within the dtype.
NumPy
numpy.org › devdocs › user › basics.types.html
Data types — NumPy v2.6.dev0 Manual
NumPy generally returns elements of arrays as array scalars (a scalar with an associated dtype). Array scalars differ from Python scalars, but for the most part they can be used interchangeably (the primary exception is for versions of Python older than v2.x, where integer array scalars cannot act as indices for lists ...
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.dtype.html
numpy.dtype — NumPy v2.1 Manual
Boolean indicating whether the byte order of this dtype is native to the platform. ... The element size of this data-type object. ... A character code (one of ‘biufcmMOSUV’) identifying the general kind of data. ... Either None or a readonly dictionary of metadata (mappingproxy). ... A bit-width name for this data-type. ... Ordered list ...
TutorialsPoint
tutorialspoint.com › numpy › numpy_data_types.htm
NumPy - Data Types
Original array: ['1.1' '2.2' 'three' '4.4' '5.5'] Original dtype: <U5 Converted array: [1.1 2.2 nan 4.4 5.5] Converted dtype: float64 · You can also convert the data type of existing arrays using the view() method to change the interpretation of the data without changing the underlying bytes. Here, the data is reinterpreted as "float32", resulting in unexpected values because the underlying bytes remain unchanged − · import numpy as np # Creating an array of integers g = np.array([1, 2, 3, 4], dtype=np.int32) print("Original array:", g) print("Original dtype:", g.dtype) # Viewing the array as float32 g_view = g.view(np.float32) print("Viewed array:", g_view) print("Viewed dtype:", g_view.dtype)
NumPy
numpy.org › doc › 2.2 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.2 Manual
The offsets value is a list of byte offsets (limited to ctypes.c_int) for each field, while the titles value is a list of titles for each field (None can be used if no title is desired for that field). The titles can be any object, but when a str object will add another entry to the fields dictionary keyed by the title and referencing the same field tuple which will contain the title as an additional tuple member. The itemsize key allows the total size of the dtype to be set, and must be an integer large enough so all the fields are within the dtype.
University of Texas at Austin
het.as.utexas.edu › HET › Software › Numpy › reference › generated › numpy.dtype.html
numpy.dtype — NumPy v1.9 Manual
>>> np.dtype((np.int16, {'x':(np.int8,0), 'y':(np.int8,1)})) dtype(('<i2', [('x', '|i1'), ('y', '|i1')]))
NumPy
numpy.org › devdocs › reference › generated › numpy.dtype.names.html
numpy.dtype.names — NumPy v2.5.dev0 Manual
dtype.names# Ordered list of field names, or None if there are no fields. The names are ordered according to increasing byte offset. This can be used, for example, to walk through all of the named fields in offset order. Examples · Try it in your browser! >>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))]) >>> dt.names ('name', 'grades') Go BackOpen In Tab ·
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.dtype.names.html
numpy.dtype.names — NumPy v2.2 Manual
Ordered list of field names, or None if there are no fields. The names are ordered according to increasing byte offset. This can be used, for example, to walk through all of the named fields in offset order. ... >>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))]) >>> dt.names ...
Programiz
programiz.com › python-programming › numpy › datatypes
NumPy Data Types (With Examples)
Here's the list of most commonly used numeric data types in NumPy: int8, int16, int32, int64 - signed integer types with different bit sizes · uint8, uint16, uint32, uint64 - unsigned integer types with different bit sizes · float32, float64 - floating-point types with different precision ...
Numpy
numpy.net › doc › stable › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v1.26 Manual
The offsets value is a list of byte offsets (limited to ctypes.c_int) for each field, while the titles value is a list of titles for each field (None can be used if no title is desired for that field). The titles can be any object, but when a str object will add another entry to the fields dictionary keyed by the title and referencing the same field tuple which will contain the title as an additional tuple member. The itemsize key allows the total size of the dtype to be set, and must be an integer large enough so all the fields are within the dtype.
NumPy
numpy.org › doc › 2.3 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.3 Manual
The offsets value is a list of byte offsets (limited to ctypes.c_int) for each field, while the titles value is a list of titles for each field (None can be used if no title is desired for that field). The titles can be any object, but when a str object will add another entry to the fields dictionary keyed by the title and referencing the same field tuple which will contain the title as an additional tuple member. The itemsize key allows the total size of the dtype to be set, and must be an integer large enough so all the fields are within the dtype.