Skillbox recommends: Practical course "Python-developer from scratch . "
We remind: for all readers of "Habr" - a discount of 10,000 rubles when recording for any Skillbox course on the promotional code "Habr".
import numpy as np
# python array a = [1,2,3,4,5,6,7,8,9] # numpy array A = np.array([1,2,3,4,5,6,7,8,9])
print(a) print(A) ==================================================================== [1, 2, 3, 4, 5, 6, 7, 8, 9] [1 2 3 4 5 6 7 8 9]
np.arange(0,10,2) ==================================================================== array([0, 2, 4, 6, 8])
np.arange(2,29,5) ==================================================================== array([2, 7, 12, 17, 22, 27])
array([2, 7, 12], [17, 22, 27])
A = [1, 2, 3, 4, 5, 6, 7, 8, 9] A.shape ==================================================================== (9,)
A = [1, 2, 3, 4, 5, 6, 7, 8, 9] A.reshape(1,9) ==================================================================== array([[1, 2, 3, 4, 5, 6, 7, 8, 9]])
B = [1, 2, 3, 4, 5, 6, 7, 8, 9] B.reshape(3,3) ==================================================================== array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
B.shape ==================================================================== (3,3)
np.zeros((4,3)) ==================================================================== ???????????
np.zeros((4,3)) ==================================================================== array([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.], [0., 0., 0.]])
np.eye(5) ==================================================================== array([[1., 0., 0., 0., 0.], [0., 1., 0., 0., 0.], [0., 0., 1., 0., 0.], [0., 0., 0., 1., 0.], [0., 0., 0., 0., 1.]])
# generate an identity matrix of (3 x 3) I = np.eye(3) I ==================================================================== array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) # generate another (3 x 3) matrix to be multiplied. D = np.arange(1,10).reshape(3,3) D ==================================================================== array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
# perform actual dot product. M = np.dot(D,I) M ==================================================================== array([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]])
# add all the elements of matrix. sum_val = np.sum(M) sum_val ==================================================================== 45.0
# sum along the rows np.sum(M,axis=1) ==================================================================== array([ 6., 15., 24.])
# sum along the cols np.sum(M,axis=0) ==================================================================== array([12., 15., 18.])
Skillbox recommends:
- Online course "Python-developer from scratch . "
- Practical annual course "PHP-developer from scratch to PRO" .
- Educational online course "Profession Java developer" .
Source: https://habr.com/ru/post/422423/