recarray from record has no shape, cannot be sliced.
See original GitHub issueCreating new recarrays from a single record results in a recarray with shape = (). It cannot be indexed into and it has no length. For now I’m working around this by reshaping the new recarray to (1,).
Reproducing code example:
import numpy as np
ra = np.rec.array(np.ones(4, dtype='f4,f4'))
r = ra[0]
ra2 = np.core.records.array(r)
ra2.shape # returns ()
ra2[0]
# np.array_equal(ra2.reshape(1,)[0], ra[0]) # True
Error message:
Traceback (most recent call last):
File "/home/chad/miniconda3/envs/np/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-19-18a4fa8bb93d>", line 6, in <module>
ra2[0]
File "/home/chad/miniconda3/envs/np/lib/python3.6/site-packages/numpy/core/records.py", line 505, in __getitem__
obj = super(recarray, self).__getitem__(indx)
IndexError: too many indices for array
Numpy/Python version information:
1.14.3 3.6.3 |Intel Corporation| (default, May 4 2018, 04:22:28) [GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
numpy recarray from CSV dtype has many columns but shape ...
A recarray is an array of records. Each record can have multiple fields. A record is sort of like a struct in C....
Read more >[Solved]-NumPy "record array" or "structured array" or "recarray ...
It first it tries to get a regular attribute - things like .shape , .strides , .data , as well as all the...
Read more >numpy.recarray — NumPy v1.24 Manual
By default, a new array is created of the given shape and data-type. ... compared to empty : it creates a new record...
Read more >NumPy User Guide
It is a Python library that provides a multidi- mensional array object, various derived objects (such as masked arrays and matrices), and an ......
Read more >FITS File handling (astropy.io.fits)
The headers will still be accessible after the HDUList is closed. The data may or may not be accessible depending on whether the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Good find on that archive page! I’m thinking we should revive that as an informational NEP, perhaps? @mattip?
There was also a pretty long discussion on the mailing list back around the time of the first NumPy release, I forget who pushed the idea, it was one of the early contributors.