数学对象
import numpy as np
scalar_value = 18
print(scalar_value)
scalar_np = np.array(scalar_value)
print(scalar_np, scalar_np.shape)
18
18 ()
vector_value = [1,2,3]
vector_np = np.array(vector_value)
print(vector_np, vector_np.shape)
[1 2 3] (3,)
matrix_list = [[1,2,3],[4,5,6]]
matrix_np = np.array(matrix_list)
print('matrix_list=', matrix_list, '\n',
'matrix_np=\n', matrix_np, '\n',
'matrix_np.shape=', matrix_np.shape)
matrix_list= [[1, 2, 3], [4, 5, 6]]
matrix_np=
[[1 2 3]
[4 5 6]]
matrix_np.shape= (2, 3)
vector_row = np.array([[1,2,3]])
print(vector_row, 'shape=',vector_row.shape)
[[1 2 3]] shape= (1, 3)
vector_column = np.array([[4],[5],[6]])
print(vector_column, 'shape=', vector_column.shape)
[[4]
[5]
[6]] shape= (3, 1)
vector_row = np.array([[1,2,3]])
print(vector_row, 'shape=',vector_row.shape, '\n', vector_row.T, '.Tshape=', vector_row.T.shape)
[[1 2 3]] shape= (1, 3)
[[1]
[2]
[3]] .Tshape= (3, 1)
matrix_a = np.array([[1,2,3],[4,5,6]])
print(matrix_a, 'shape=', matrix_a.shape)
[[1 2 3]
[4 5 6]] shape= (2, 3)
matrix_b = matrix_a * 2
print(matrix_b, 'shape=', matrix_b.shape)
[[ 2 4 6]
[ 8 10 12]] shape= (2, 3)
matrix_c = matrix_a+2
print(matrix_c, 'shape=',matrix_c.shape)
[[3 4 5]
[6 7 8]] shape= (2, 3)
matrix_a = np.array([[1,2,3],
[4,5,6]])
matrix_b = np.array([[-1,-2,-3],
[-4,-5,-6]])
matrix_a + matrix_b
array([[0, 0, 0],
[0, 0, 0]])
matrix_a = np.array([[1,2,3],
[4,5,6]])
matrix_b = np.array([[-1,-2,-3],
[-4,-5,-6]])
matrix_a * matrix_b
array([[ -1, -4, -9],
[-16, -25, -36]])
matrix_a = np.array([[1,2,3],
[4,5,6]])
matrix_b = np.array([[1,2,3,4],
[2,1,2,0],
[3,4,1,2]])
np.matmul(matrix_a, matrix_b)
array([[14, 16, 10, 10],
[32, 37, 28, 28]])