---
title: "Explain the NumPy Array Shape"  
description: "Explain the NumPy Array Shape"  
author: "ICSM Computer"  
published: 2025-11-10  
updated: 2025-11-10  
canonical: https://www.mindstick.com/interview/34410/explain-the-numpy-array-shape  
category: "python"  
tags: ["python-3.4", "numpy", "Python 3"]  
reading_time: 3 minutes  

---

# Explain the NumPy Array Shape

> In [**NumPy**](https://www.mindstick.com/interview/34402/introduction-to-numpy), the **shape** of an array tells you **how many elements** it has along **each dimension** (rows, columns, etc.).

### Syntax

```python
array.shape
```

### Example 1: 1D Array

```python
import numpy as np

arr = np.array([10, 20, 30, 40])
print(arr.shape)
```

## Output:

```plaintext
(4,)
```

This means the array has **4 elements** in **1 dimension**.

### Example 2: 2D Array

```python
arr = np.array([[1, 2, 3],
                [4, 5, 6]])
print(arr.shape)
```

## Output:

```plaintext
(2, 3)
```

This means there are **2 rows** and **3 columns**.

### Example 3: 3D Array

```python
arr = np.array([
    [[1, 2], [3, 4]],
    [[5, 6], [7, 8]]
])
print(arr.shape)
```

## Output:

```plaintext
(2, 2, 2)
```

This means there are **2 blocks**, each containing a **2×2** matrix.

### Example 4: Using `.reshape()` to change shape

```python
arr = np.array([1, 2, 3, 4, 5, 6])
new_arr = arr.reshape(2, 3)
print(new_arr)
print(new_arr.shape)
```

## Output:

```plaintext
[[1 2 3]
 [4 5 6]]
(2, 3)
```

### Example 5: Get number of dimensions

```python
print(arr.ndim)
```

## Output:

```plaintext
1
```

Returns the **number of dimensions**.

### Summary

| Property | Meaning | Example Result |
| --- | --- | --- |
| `arr.shape` | Returns shape (rows, cols, etc.) | `(3, 4)` |
| `arr.ndim` | Returns number of dimensions | `2` |
| `arr.size` | Returns total number of elements | `12` |

## Answers

### Answer by ICSM Computer

> In [**NumPy**](https://www.mindstick.com/interview/34402/introduction-to-numpy), the **shape** of an array tells you **how many elements** it has along **each dimension** (rows, columns, etc.).

### Syntax

```python
array.shape
```

### Example 1: 1D Array

```python
import numpy as np

arr = np.array([10, 20, 30, 40])
print(arr.shape)
```

## Output:

```plaintext
(4,)
```

This means the array has **4 elements** in **1 dimension**.

### Example 2: 2D Array

```python
arr = np.array([[1, 2, 3],
                [4, 5, 6]])
print(arr.shape)
```

## Output:

```plaintext
(2, 3)
```

This means there are **2 rows** and **3 columns**.

### Example 3: 3D Array

```python
arr = np.array([
    [[1, 2], [3, 4]],
    [[5, 6], [7, 8]]
])
print(arr.shape)
```

## Output:

```plaintext
(2, 2, 2)
```

This means there are **2 blocks**, each containing a **2×2** matrix.

### Example 4: Using `.reshape()` to change shape

```python
arr = np.array([1, 2, 3, 4, 5, 6])
new_arr = arr.reshape(2, 3)
print(new_arr)
print(new_arr.shape)
```

## Output:

```plaintext
[[1 2 3]
 [4 5 6]]
(2, 3)
```

### Example 5: Get number of dimensions

```python
print(arr.ndim)
```

## Output:

```plaintext
1
```

Returns the **number of dimensions**.

### Summary

| Property | Meaning | Example Result |
| --- | --- | --- |
| `arr.shape` | Returns shape (rows, cols, etc.) | `(3, 4)` |
| `arr.ndim` | Returns number of dimensions | `2` |
| `arr.size` | Returns total number of elements | `12` |


---

Original Source: https://www.mindstick.com/interview/34410/explain-the-numpy-array-shape

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
