What is a NumPy Array?
- A NumPy array is a collection of values stored in a structured way.
Numpy also supports:
1D arrays
2D arrays
3D arrays
Higher-dimensioanl arrays
Access Array Elements
- We can access individual elements using their index.
arr = np.array([10, 20, 30, 40])
print(arr[0])
print(arr[3])
Output:
10
40
Array Slicing
- Slicing is used to extract a portion of an array.
arr = np.array([10, 20, 30, 40])
print(arr[0:3])
Output:
[10 20 30]
1D Array
- A 1D array contains values in a single row.
Output:
Attributes:
Output:
2D Array
- A 2D array contains rows and columns.
Output:
Attributes:
Output:
3D Array
- NumPy can also create 3D arrays.
Output:
Attributes:
Output:












Top comments (0)