Lessons

- Python Dictionaries
- Comparison Operators in Python
- Logical Operators in Python
- Conditional Statements in Python
- For Loop in Python
- While Loop in Python
- How to loop over python dictionaries and Numpy arrays
- What is NumPy in Python
- ndarray - Methods and Data Type
- NumPy - Methods to Create Arrays
- Python NumPy - Numerical Operations on Arrays
- Python NumPy - Indexing and Slicing Arrays

# ndarray - Methods and Data Type

Once you have created an array, you can check its various attributes using the inbuilt functions. Some of these are described below:

### ndarray.ndim

Returns the number of array dimensions.

```
>>> a
array([[ 1., 2., 3.],
[ 4., 5., 6.]])
>>> a.ndim
2
>>> x = np.array([1, 2, 3])
>>> x.ndim
1
```

### ndarray.shape

Returns a tuple of array dimensions. It can also be used to "reshape" the array, as long as this would not require a change in the total number of elements.

```
>>> a.shape
(2, 3)
>>> x.shape
(3,)
>>> a.shape = (3,2)
>>> a
array([[ 1., 2.],
[ 3., 4.],
[ 5., 6.]])
```

### ndarray.size

Returns the number of elements in the array. This can also be calculated with `np.prod(a.shape)`

, i.e., the product of the array’s dimensions.

# This content is for paid members only.

Join our membership for lifelong unlimited access to all our data science learning content and resources.