【发布时间】:2020-02-20 13:31:23
【问题描述】:
我有下一个功能:
def check_smaller_zeros(v):
return v < 0
当我使用 numpy 创建数组时,我可以为逐个元素的测量编写下一个代码:
v_1 = numpy.array([1, 2, -4, -1])
result = check_smaller_zeros(v_1)
# result: [False, False, True, True]
但是当我尝试使用 tuple、set、frozenset 和 list/array reise 重复它时,下一个错误:
TypeError: '<' not supported between instances of 'tuple' and 'int'
究竟是什么让 numpy 数组具有这种行为的能力?这看起来很方便,但有点不明显
【问题讨论】:
-
你可以在broadcasting找到这个
标签: python numpy data-structures