如何将numpy“高级索引”与`np.newaxis`结合起来?

时间:2013-02-20 08:19:00

标签: python numpy

如何将numpy“高级索引”与np.newaxis结合使用?

import numpy as np
a = np.zeros(10)
b = np.zeros(10, dtype=np.bool_)
b[4] = True
print(a[b])  # [ 0.]
print(a[b][:, np.newaxis])  # [[ 0.]]  (works, but this is inelegant)
print(a[b, np.newaxis])  # TypeError: int() argument must be a string or a number, not 'NoneType'

0 个答案:

没有答案