numpy / numpy/numpy

Support for field-major initialization of Record Arrays `np.rec.array(tuple(lists))`

Open
#12,761 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

Request: A convenient (documented) way to construct record arrays from field-major data.

Right now we support AOS (arrays of structs). This request is for SOA (struct of arrays). Just for initialization. Representation remains untouched.

Motivating Example
import numpy as np
x1 = {'header1': [values1], 'header2': [values2]}
x2 = ([values1], [values2])
headers = ('header1', 'header2')

assert all(x1[h].shape == x1[headers[0]].shape for h in headers)
assert len(headers) == len(x2)
assert all(x.shape == x2[0].shape for x in x2)

r1 = np.rec.array(x1)
r2 = np.rec.array(x2, names=headers)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the np.rec.array entry point and trace how tuple and names arguments are currently handled. Define the field-major initialization behavior shown in the motivating example, then add coverage for tuple-of-lists input and matching field names; done means the example works without changing the record-array representation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.