These are chat archives for numpy/numpy

Aug 2017
André Szabolcs Szelp
Aug 02 2017 20:23

X=np.fromfunction(lambda i, k, h: min(i+k-h, k), (3,2,3)) gives me:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all(), which I do not get.

I mean, it's probably some stupid typo, but I just don't get it.

Nathaniel J. Smith
Aug 02 2017 21:53
@szabi: it's ending up passing arrays for i, k, h, and then you're passing them to the python built-in min function, which does not know what to do with arrays
specifically it's trying to do if a < b: a else b but when a and b are arrays, this doesn't work, because some elements are true, and some are false
Denis Lisov
Aug 02 2017 21:55
Maybe use numpy.minimum instead of min?
André Szabolcs Szelp
Aug 02 2017 22:52
But I must say, the documentation is misunderstandable! It sounds like taking a "normal" function and applying it elementwise! "Construct an array by executing a function over each coordinate."
Heh, I just found out by accident, that typing a regex-style s/oldtext/newtext/ will actually edit/update your last message here in gitter. Wow! (And geeky).