facebook
online numpy

Numpy – NDARRAY OBJECT

The most important object defined in Numpy is the N-dimensional array type also ndarray. It describes the collection of items of the same type. Items in the collection can access using a zero-based index.

Every item in a ndarray Takes the same size as the block in the memory. Each element in ndarray is an object of data-type object (called dtype).

Any item extracted from the ndarray object ( by slicing ) represents the python object of the array scalar types. The following diagram shows a relationship between ndarray and data-type object (dtype) and array scalar type:

Numpy - NDARRY Object
How Numpy – NDARRAY OBJECT works.

An instance of ndarray class can be constructed in different array creation routines described Later in the tutorial. The basic ndarray created using an array function in Numpy is as follows:

numpy.array

It Creates a ndarray from any object exposing array interface, or from any method that returns an array.

numpy. array (object, dtype = None, copy = true, order = none, subok = false, ndmin = 0)

The above constructor Takes the following Parameters for NDARRAY:

ObjectAny object exposing the array interface method returns an array, or any (nested) sequence
dtypeThe desired data type of array, optional
copyOptional. By default (true), the object is copied
orderC (row major) or F (column major) or A (any) (default)
subokBy default, returned array is forced to be a base class array. If true, sub-classes passed through
ndiminSpecifies minimum dimensions of the resultant array

The following examples on Numpy – NDARRAY OBJECT

Example 1

Import numpy as np 

a=np. Array ((1,2,3 ))

Print a

Output:

(1, 2, 3)

Example 2

# minimum dimensions 

Import numpy as np 

a = np. array ( ( 1 , 2, 3, 4 , 5 ) , ndmin = 2 ) 

Print a

Output:

( ( 1,  2,  3,  4, 5 ) )

The ndarray object consists of a contiguous – dimensional segment of computer memory, combined with an indexing scheme that maps each item to a location in the memory block. The memory block holds the elements in row-major order (c style) or a column-major order ( Fortran or Matlab style ).

Leave a Comment

Your email address will not be published. Required fields are marked *

Analogicx

FREE
VIEW