Questions tagged [recarray]

A *rec*ord *array* in the python package numpy - think of as a table with column names.

A record array is particular to the numpy package. It is essentially an ndarray that can be accessed by associative indices.

Ex: create an array with two fields, 'x' (float) and 'y' (int):

>>> ra = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', float), ('y', int)])
>>> ra
array([(1.0, 2), (3.0, 4)],
      dtype=[('x', '<f8'), ('y', '<i4')])
>>> ra['x']
array([ 1.,  3.])
>>> ra[0]['y']
2

See the recarray help page and cookbook.

103 questions
1
vote
1 answer

Specifying a numpy.datype to read GPX trackpoints

I want to represent a GPS track extracted from GPX file as a Numpy array. For that, each element will be of type "trackpoint", containing one datetime and three floats. I am trying to do this (actually, after parsing the GPX file with some XML…
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
1
vote
2 answers

Fancy indexing of numpy recarray lost reference after assignment

I found a strange situation with my code and the issue is shown in the code bellow import numpy as np dt = dict(names = ['n1','n2'], formats = ['a8','int']) reca = np.recarray((10,), dtype = dt) reca['n1'] =…
guofeng
  • 15
  • 3
1
vote
1 answer

numpy, recarray: Methods to convert a list of dict's to a np.recarray?

What methods are available to convert a loosely coupled list of dictionaries to a np.recarray (where import numpy as np)? I looked around here on SO, but namely saw things where the data was already well-structured. I've prototyped a simple method…
eacousineau
  • 3,457
  • 3
  • 34
  • 37
1
vote
1 answer

Calculating conditional probabilities from joint pmfs in numpy, too slow. Ideas? (python-numpy)

I have a conjunctive probability mass function array, with shape, for example (1,2,3,4,5,6) and I want to calculate the probability table, conditional to a value for some of the dimensions (export the cpts), for decision-making purposes. The code I…
mhourdakis
  • 179
  • 8
1
vote
2 answers

Splitting record array into sub-arrays, shuffling them, and then recombining them into CSV file

Apologies in advance if the question is poorly written. This is my second post ever onto the site and I'm a novice programmer. To start, here's what I'm aiming to do: Step 0: Turn CSV File into record array Step 1: Split record array into two…
1
vote
1 answer

Adding new records to a numpy structured array

This is a continuation of an earlier learning on numpy arrays. A structured array is created from the elements of a list - and thereafter populated with values(not shown below). >>> o = ['x','y','z'] >>> import numpy as np >>> b =…
IUnknown
  • 9,301
  • 15
  • 50
  • 76
1
vote
3 answers

Slicing numpy recarray at "empty" rows

I created a numpy.recarray from a .csv-Inputfile using the csv2rec()-Method. The Inputfile and consequently the recarray have empty rows with no data (resp. nan-values). I want to slice this recarray at the nan-rows into multiple sub-arrays,…
ala
  • 224
  • 3
  • 16
1
vote
1 answer

numpy recordarray with times?

I'm trying to read an XML file into a NumPy record array. Times are in Zulu time, u'2013-06-06T17:47:38Z', and the other columns are floats. The times and the floats can both be converted into NumPy arrays. However, if I try to make a recordarray,…
keflavich
  • 18,278
  • 20
  • 86
  • 118
1
vote
2 answers

Add hierarchy to numpy structured array

I would like to take an existing array with several named fields, and create a new array (or change it in place) with one field with a hierarchical dtype equal to the original dtype. That is, newarray = np.array(oldarray,…
askewchan
  • 45,161
  • 17
  • 118
  • 134
0
votes
0 answers

Python - numpy recarray - type string missing

I am using a recarray loader which takes a dict of values as an argument. The string type is never passed to the array, yet clearly visible when creating the array: My loader class: import numpy as np class Loader(np.recarray): def __new__(_,…
Freelax FPV
  • 5
  • 1
  • 2
0
votes
0 answers

Python in R with reticulate - cannot acccess numpy.recarray object due to "Error in py_ref_to_r(x)"

My team is working on a R project that imports a Python pacakge with reticulate. One of the Python function generates some important output stored in a numpy.recarray object. We have been trying to access the reacrray in R without any success, and…
0
votes
1 answer

Python - numpy - use somes recarray by json in one recarray

My goal is to achieve simplified access to the various json files, with recarrays in a global recarray to achieve simplified end access like: parms.logic.myVarA. Desired structure parms (recarray) [ logic (recarray) - myVarA (int) …
Freelax FPV
  • 5
  • 1
  • 2
0
votes
1 answer

How to sort numpy.recarray based on datetime field

I have built a recarray with np.rec.fromarrays and following structure : dtype=np.dtype([('layers', 'U256'), ('hours', datetime.datetime), ('points', 'U256')])) I get an object like this : [('image1.jpg', datetime.datetime(1900, 1, 1, 21, 20),…
dmjf08
  • 143
  • 7
0
votes
2 answers

Python, create numpy recarray efficiently

today I am using this code to create a numpy recarray. I am pretty sure it can be done more code efficient. But not exactly sure how to. The input is t and p. Each step says how many seconds and how much power. output is an recarray in seconds. ##…
Jakob
  • 47
  • 4
0
votes
1 answer

How to add or construct nested numpy structured array from existing structures

In general, my question is on the possible ways for creating/appending to nested structured arrays. Specifically where the dtype structure is known, but the size in the nested elements weren't pre-defined. I have tried different things with the…
001001
  • 530
  • 1
  • 4
  • 13