Satish Dangi
Satish Dangi
Satish Dangi
import numpy as np
data1 = [6, 7.5, 8, 0, 1]
arr1 = np.array(data1)
print(arr1)
print(arr1.dtype)
print(arr1.shape)
print(arr1.ndim)
Creating ndarrays
import numpy as np
print(arr * arr)
[[ 1. 4. 9.]
[16. 25. 36.]]
print(arr - arr)
[[0. 0. 0.]
[0. 0. 0.]]
Arithmatic with NumPy Arrays
print(arr **2)
• [[Comparisons
1. 4. 9.] between arrays of the same size yield boolean
arrays:
[16. 25. 36.]]
arr = np.arange(10)
print(arr) # [0 1 2 3 4 5 6 7 8 9]
arr_slice = arr[5:8]
print(arr_slice) # [5 6 7]
arr_slice[1] = 12345
print(arr) # [ 0 1 2 3 4 5 12345 7 8 9]
arr_slice[:] = 64
print(arr) # [ 0 1 2 3 4 64 64 64 8 9]
Indexing
print(arr2d[0][2]) #3
print(arr2d[0, 2]) #3
Activity 3