You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[8], line 4
2 b = np.ones(s, dtype=bool)
3 p = np.arange(s)[a]
----> 4 b[p ** 2::p] = False
TypeError: only integer scalar arrays can be converted to a scalar index
Python and NumPy Versions:
1.26.4
3.12.8 (main, Dec 3 2024, 18:42:41) [GCC 13.3.0]
What phrasing would have helped you more? IMO the current message describes what the issue is. Keep in mind that some arrays (those with shape ()) can be used as a scalar index:
In [3]: a = np.zeros(10)
In [4]: i = np.array(2)
In [5]: a[i::i] = 1
In [6]: a
Out[6]: array([0., 0., 1., 0., 1., 0., 1., 0., 1., 0.])
In [7]: i.shape
Out[7]: ()
It is possible to do what (I think?) you were trying to do but it requires using advanced indexing.
There's certainly room to make the error message more clearly communicate what the fundamental issue is: when you use the start:stop:step style indexing, NumPy treats the indices as scalars.
Feel free to reopen the issue btw, there's always room to make errors clearer. I was just trying to point out that there are some subtleties.
Describe the issue:
When attempting to use arrays as slices, NumPy gives a message that doesn't accurately describe the actual problem.
Reproduce the code example:
Error message:
Python and NumPy Versions:
1.26.4
3.12.8 (main, Dec 3 2024, 18:42:41) [GCC 13.3.0]
Runtime Environment:
[{'numpy_version': '1.26.4',
'python': '3.12.8 (main, Dec 3 2024, 18:42:41) [GCC 13.3.0]',
'uname': uname_result(system='Linux', node='nixos', release='6.6.30-rt30', version='#1-NixOS SMP PREEMPT_RT Thu May 2 14:32:50 UTC 2024', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL',
'AVX512_SPR']}},
{'filepath': '/nix/store/mhd0rk497xm0xnip7262xdw9bylvzh99-gcc-13.3.0-lib/lib/libgomp.so.1.0.0',
'internal_api': 'openmp',
'num_threads': 2,
'prefix': 'libgomp',
'user_api': 'openmp',
'version': None}]
Context for the issue:
I found this issue while playing around with NumPy, and it really confused me. I think people may get equally confused when doing some actual work.
The text was updated successfully, but these errors were encountered: