我正在尝试这样做:
X = U[(U > lims[0] & U < lims[1])] #U is numpy array输出:
Traceback (most recent call last):
File "Ha.py", line 19, in <module>
X = U[(U > lims[0] & U < lims[1])]
TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''但
X = U[(U > lims[0])效果很好。
怎么啦?我该如何优雅地克服这一点呢?
发布于 2020-09-07 19:33:52
当你尝试像这样的东西时:
X = U[(U > lims[0] & U < lims[1])] Numpy认为您正在尝试执行按位操作。这是因为逐位&运算比条件>运算具有更高的优先级。
你应该尝试类似这样的东西:
X = U[(U > lims[0]) & (U < lims[1])]https://stackoverflow.com/questions/63776736
复制相似问题