Learn Before
Code
Common Initializing methods in Numpy
- np.array() convert python array to ndarray
li = [1,2,3,4,5,6] arr = np.array(li) # convert to nd array display(arr)
- np.arange() Similar to python range, but returns an ndarray type.
np.arange(1,7) array([1, 2, 3, 4, 5, 6])
- np.zeros(), np.full(), np.eye() basic matrix creation methods.
> np.zeros((2,3)) array([[0., 0.], [0., 0.], [0., 0.]]) > np.full((2,3), 55) # 2 and 3 represents the dimensions, 55 representing the element. array([[55, 55, 55], [55, 55, 55]]) > np.eye(2) # diagonally filling the inputted parameter array([[1., 0.], 0., 1.])
0
3
Updated 2020-09-05
Tags
Data Science