numpy.linalg.norm给出了奇怪的结果。

4
以下代码出错:
print numpy.linalg.norm(2) # returns 2
print numpy.linalg.norm(2, np.inf) # returns error,
print numpy.linalg.norm(2, np.inf) # returns the same error:

ValueError: Improper number of dimensions to norm.

如何将上述规范用于非NumPy数组输入?
1个回答

7

正如文档字符串所述:

In [165]: np.linalg.norm?
Definition: np.linalg.norm(x, ord=None, axis=None)   
...    
Parameters
----------
x : array_like
    Input array.  If `axis` is None, `x` must be 1-D or 2-D.
norm的第一个参数应该是类似于数组的对象。因此,请使用
In [167]: np.linalg.norm([2], np.inf)
Out[167]: 2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接