0

When trying to create a numpy structured array with the code below:

import numpy as np
z = np.zeros([3,3], dtype=[("x",float)])
print(z)

I'm getting two Future Warnings:

sys:1: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
sys:1: FutureWarning: elementwise == comparison failed and returning scalar  instead; this will raise an error or perform elementwise comparison in the future.

I know about a stand off between Numpy and Python developers regarding the comparison of data types that led to this warning (as can be read here: FutureWarning: elementwise comparison failed; returning scalar, but in the future will perform elementwise comparison) but I'm wondering why this Warning is being raised if I'm not doing any comparison, just trying to create a structured array.

The numpy version in use is 1.21.2

Gustavo Mirapalheta
  • 931
  • 2
  • 11
  • 25
  • Can you provide exact version of NumPy? – jdworzans Feb 06 '22 at 12:56
  • The numpy version is 1.21.2 – Gustavo Mirapalheta Feb 06 '22 at 13:53
  • I don't think it's the `z` creation that causing the warning, but rather a subsequent `z==0` like action. Most operators don't work on a whole structured array, though they may work on individual fields, `z['x']==0`. – hpaulj Feb 06 '22 at 16:38
  • I'm getting the FutureWarning straight from the creation of the `z` array. I understand your point, but I don't see how can this be the case here, since there's no other code besides the one I presented. On the other hand, would it be possible that the machinery of creating a structured array in Numpy is somehow making some kind of check when the user creates a structured array, such that this comparison is being made? – Gustavo Mirapalheta Feb 06 '22 at 16:47
  • I don't get this warning on `.1.22.0` (and py 3.8) – hpaulj Feb 06 '22 at 19:36
  • Here's an example of the warning with a structured array comparison, https://stackoverflow.com/questions/68869145/finding-matching-subset-of-row-in-a-numpy-structured-array. I don't see evidence of anyone else getting such a warning while simply creating a structured array. – hpaulj Feb 06 '22 at 20:01

0 Answers0