我想用numpy来得到向量的范数。通过使用数组或矩阵,我得到了不同的结果。你知道吗
如果a=np.数组([3,4]),结果正确:n1=7,n2=5,ninf=4。你知道吗
如果a=np.矩阵('3 4')结果不正确:n1=4,n2=5,ninf=7
有人能告诉我下面的代码有什么问题吗?谢谢。你知道吗
import numpy as np
a = np.matrix('3 4')
n1 = np.linalg.norm(a,ord=1)
n2 = np.linalg.norm(a,ord=2)
ninf = np.linalg.norm(a,ord = np.inf)
print(repr(n1)) # should be 7
print(repr(n2)) # should be 5
print(repr(ninf)) # should be 4
目前没有回答
相关问题 更多 >
编程相关推荐