如何在NumPy中优雅地规范化向量列表?
下面是一个不起作用的例子:
from numpy import *
vectors = array([arange(10), arange(10)]) # All x's, then all y's
norms = apply_along_axis(linalg.norm, 0, vectors)
# Now, what I was expecting would work:
print vectors.T / norms # vectors.T has 10 elements, as does norms, but this does not work
最后一个操作产生“形状不匹配:对象不能广播到单个形状”。
如何使用NumPy优雅地对vectors
中的2D向量进行标准化?
编辑:为什么在向norms
添加维度时上面的操作不起作用(根据我下面的答案)?
https://stackoverflow.com/questions/2850743
复制相似问题