python自学笔记1

列表的形式:

import numpy
matrix1 = numpy.array([[1, 2, 3, 4],
           [5, 6, 7, 8],
           [9, 10, 11, 12]])
print(matrix1)

matrix2 = numpy.array([[1, 3, 3, 4],
           [5, 4, 7, 8],
           [9, 60, 11, 12]])
print(matrix2)

matrix1c = matrix1 * matrix2
print("matrix1", matrix1)
print("matrix2", matrix2)
print("matrix1c", matrix1c)

列表结果:

matrix1 [[ 1  2  3  4]
 [ 5  6  7  8]
 [ 9 10 11 12]]
matrix2 [[ 1  3  3  4]
 [ 5  4  7  8]
 [ 9 60 11 12]]
matrix1c [[  1   6   9  16]
 [ 25  24  49  64]
 [ 81 600 121 144]]

矩阵的形式:

matrix11 = mat([[1, 34, 3, 4],
           [5, 6, 7, 8],
           [9, 10, 11, 12]])

matrix22 = mat([[1, 56, 3],
           [5, 4, 7],
           [9, 60, 11],
               [9, 60, 11]])

matrix1cc = matrix11 * matrix22
print("matrix11", matrix11)
print("matrix22", matrix22)
print("matrix1cc", matrix1cc)

矩阵结果:

matrix11 [[ 1 34  3  4]
 [ 5  6  7  8]
 [ 9 10 11 12]]
matrix22 [[ 1 56  3]
 [ 5  4  7]
 [ 9 60 11]
 [ 9 60 11]]
matrix1cc [[ 234  612  318]
 [ 170 1204  222]
 [ 266 1924  350]]

你可能感兴趣的:(python自学笔记1)