NumPy Array Attributes - NumPy

What are the different array attributes of NumPy?

The different array attributes of NumPy are as follows:

ndarray.shape

A tuple which consist of array dimensions is returned by this array attribute of adarray.shape. The array can also be resized by using this array attribute.

Example 1

The output appears as:

Example 2

The output appears as:

Example 3

To resize an array, a reshape function is also provided by NumPy.

The output appears as:

ndarray.ndim

The number of array dimensions is returned by this array attribute.

Example 1

The output appears as:

Example 2

The output appears as:

numpy.itemsize

The length of each element of the array is returned by this attribute in terms of bytes.

Example 1

The output appears as:

Example 2

The output appears as:

numpy.flags

The attributes of the ndarray are as follows. This function returns the current values.

S.No
Attribute & Description
1.
C_CONTIGUOUS (C)
The data is in a single, C-style contiguous segment
2.
F_CONTIGUOUS (F)
The data is in a single, Fortran-style contiguous segment
3.
OWNDATA (O)
The array owns the memory it uses or borrows it from another object
4.
WRITEABLE (W)
The data area can be written to. Setting this to False locks the data, making it read-only
5.
ALIGNED (A)
The data and all elements are aligned appropriately for the hardware
6.
UPDATEIFCOPY (U)
This array is a copy of some other array. When this array is deallocated, the base array will be updated with the contents of this array

Example

The current value of the flags is illustrated below:

The output appears as:

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

NumPy Topics