import numpy as np data = [1, 2, 3, 4] arr = np.array(data) print(arr) # Output: [1 2 3 4]
import numpy as np a = np.array([[1,2,3],[4,5,6],[7,8,9]]) print(a[1]) # Output: [4 5 6] print(a[0:2,2]) # Output: [3 6]
import numpy as np a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) c = a + b print(c) # Output: [5 7 9]In this example, we create two ndarrays and perform an element-wise addition operation using the `+` operator. The resulting ndarray is a new array with the sum of the corresponding elements from each input array. Overall, these examples demonstrate some of the basic features and functionality of NumPy ndarrays.