question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

recarray from record has no shape, cannot be sliced.

See original GitHub issue

Creating 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:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, Oct 13, 2018

Good find on that archive page! I’m thinking we should revive that as an informational NEP, perhaps? @mattip?

0reactions
charriscommented, Oct 13, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found