NumPy

import numpy as np

arr = np.array([1, 2, 3, 4, 5, 6], dtype=np.float64) # - одномерный массив
print (arr, type(arr))
# [1 2 3 4 5 6] <class 'numpy.ndarray'>

print (arr.shape)
# (6,)

print (arr.reshape(2, 3))
# [[1 2 3]
#  [4 5 6]]

zeros = np.zeros((2,2))
print (zeros)
# [[ 0.  0.]
# [ 0.  0.]]

iden = np.eye(3) # единичная матрица

rand = np.random.random((3,3))

print (iden * rand) # поэлементое умножение
# [[ 0.28398446  0.          0.        ]
# [ 0.          0.3899033   0.        ]
# [ 0.          0.          0.74027301]]

res = iden.dot(rand)
print (res) # произведение матриц 
# [[ 0.28398446  0.89726135  0.23917508]
# [ 0.74883124  0.3899033   0.95637911]
# [ 0.91893833  0.75129598  0.74027301]]

print (res.T) # транспонирование (цифры не те, потому что новая матрица срандомилась)
# [[ 0.60598883  0.29596218  0.36182805]
# [ 0.7866258   0.79171805  0.27167152]
# [ 0.90395962  0.31414138  0.58706252]]

print (res[1,:])
# [ 0.74883124  0.3899033   0.95637911]

results matching ""

    No results matching ""