以下给出错误:
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.
Run Code Online (Sandbox Code Playgroud)
如何在非 numpy 数组输入中使用上述规范?
正如文档字符串所述:
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.
Run Code Online (Sandbox Code Playgroud)
的第一个参数norm应该是一个类似数组的对象。因此使用
In [167]: np.linalg.norm([2], np.inf)
Out[167]: 2
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6985 次 |
| 最近记录: |