关于numpy的学习;
1、随机array的产生,from numpy import *
random.rand(4, 4)
array 和 matrix是由区别的,上述操作只产生array,通过mat(random.rand(4,4))产生矩阵
看上去没什么区别,但是实际上还是有差别的,比如求逆,上述matrix就可以,但是array不可以,
如
from numpy import *
a = 100*random.rand(4, 4)
# a1 = a.I
print('a =', a, '\n', 'a.shape =', a.shape)
b = mat(random.rand(4, 4))
b1 = b.I
print('b =', b, '\n', 'b.shape =', b.shape, '\n', "对b求逆 =", b1)
c = eye(4)
print('c =', c) 结果展示: a = [[76.85152131 14.99735427 6.85834832 29.67180422] [91.6979122 32.6047075 2.32941828 31.20946478] [23.8556794 67.10700449 48.49510026 22.40238346] [45.91045544 16.53090615 66.71346077 57.11425283]] a.shape = (4, 4) b = [[0.21406897 0.69462993 0.41353914 0.97983807] [0.91408446 0.21732001 0.99534469 0.39283777] [0.85695195 0.72362135 0.48983071 0.93596663] [0.08755973 0.65319038 0.25694018 0.73399583]] b.shape = (4, 4) 对b求逆 = [[-0.89119067 -0.25944864 1.75984132 -0.91554878] [-6.14590383 0.45367467 0.27349585 7.6128321 ] [-0.04669989 1.49797574 -1.73694012 1.47550548] [ 5.59196201 -0.89715609 0.15470607 -5.81962459]] c = [[1. 0. 0. 0.] [0. 1. 0. 0.] [0. 0. 1. 0.] [0. 0. 0. 1.]] |
mat(random.rand(4, 4)).I (.I的操作是求逆)