Signature
np.array(object, dtype=None, copy=True)What it does
np.array is the most direct way to turn nested lists into a NumPy array. The dtype is inferred from the values unless you pass one explicitly. Arrays created this way own their data by default.
Parameters
objectarray_like- A list, tuple, nested sequence, or existing array.
dtypedtype, optionaloptional- The element type to store, such as float64 or int32.
copybooloptional- Whether to copy the input data.
Returns
ndarray
Example
pythonnp.array example
import numpy as np
values = np.array([1, 2, 3])
print(values)
print(values.shape)Output
[1 2 3] (3,)
Watch out for
- Lists with mixed types may be promoted to a common dtype, so check dtype when exact storage matters.
- Use np.asarray when you want to avoid an unnecessary copy of an existing array.