Functionalities and benefits of the NumPy library:
Basic structure and properties of NumPy arrays:
import numpy as np
# Creating an array
arr1 = np.array([1, 2, 3, 4, 5]) # 1D array
arr2 = np.array([[1, 2, 3], [4, 5, 6]]) # 2D array
# Accessing elements and shape
print(arr1[0]) # Output: 1
print(arr2[1, 2]) # Output: 6
print(arr1.shape) # Output: (5,)
print(arr2.shape) # Output: (2, 3)
# Reshaping an array
arr3 = np.reshape(arr1, (5, 1))
print(arr3.shape) # Output: (5, 1)
# Element-wise operations
result = arr1 + arr2
print(result) # Output: [[2 4 6] [5 7 9]]
</code>