关于使用python.numpy的tips
产生含有5个数字的随机向量时,注意写法
import numpy as np
A=np.random.randn(5,1) # 注意不要只写5 B=np.random.randn(5)与A不一样,B既不是行向量也不是列向量
# 用B=B.reshape(1,5) 将B 变成一个行向量
print(A)
输出:
[[-0.96120307] [ 1.36884942] [-1.07995251] [ 0.63780095] [-0.28281732]]
求A的转置
print(A.T)
输出:
[[-0.96120307 1.36884942 -1.07995251 0.63780095 -0.28281732]]
求内积:
print(np.dot(A,A.T))
输出:
[[ 0.92391133 -1.31574226 1.03805366 -0.61305623 0.27184488] [-1.31574226 1.87374874 -1.47829236 0.87305346 -0.38713433] [ 1.03805366 -1.47829236 1.16629741 -0.68879473 0.30542928] [-0.61305623 0.87305346 -0.68879473 0.40679005 -0.18038116] [ 0.27184488 -0.38713433 0.30542928 -0.18038116 0.07998564]]