numpy.array — NumPy v2.5 Manual
An array, any object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence. If object is a scalar, a 0- ...
An array, any object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence. If object is a scalar, a 0- ...
This is the main array creation function. Most new arrays are created with this flexible function. The returned object is an object of Python-type subtype, which must be a subtype of PyArray_Type. The array has nd dimensions, described by dims.
The second is the use of the __array_finalize__ method to allow subclasses to clean up after the creation of views and new instances from templates. A brief Python primer on __new__ and __init__ # __new__ is a standard Python method, and, if present, is called before __init__ when we create a class instance.
Most of the following examples show the use of indexing when referencing data in an array. The examples work just as well when assigning to an array. See Assigning values to indexed arrays for specific examples and explanations on how assignments work.
Notes If a formatter is specified for a certain type, the precision keyword is ignored for that type. This is a very flexible function; array_repr and array_str are using array2string internally so keywords with the same name should work identically in all three functions. Examples Try it in your browser!
Conversion from other Python structures (i.e. lists and tuples)Intrinsic NumPy array creation functions (e.g. arange, ones, zeros, etc.)Creating arrays from raw bytes through the use of strings or buffers
Figure Conceptual diagram showing the relationship between the three fundamental objects used to describe the data in an array: 1) the ndarray itself, 2) the data-type object that describes the layout of a single fixed-size element of the array, 3) the array-scalar Python object that is returned when a single element of the array is accessed. #
Return an ndarray object from a Python object that exposes the __array__ method. The __array__ method can take 0, 1, or 2 arguments ([dtype, context]) where context is used to pass information about where the __array__ method is being called from (currently only used in ufuncs).
The homogeneous N-dimensional array interface is a default mechanism for objects to share N-dimensional array memory and information. The interface consists of a Python-side and a C-side using two attributes. Objects wishing to be considered an N-dimensional array in application code should support at least one of these attributes.
A data type object (an instance of numpy.dtype class) describes how the bytes in the fixed-size block of memory corresponding to an array item should be interpreted.
NumPy reference Routines and objects by topic Functional programming Functional programming #