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
2
votes
1 answer

find close elements in numpy recarray

I am trying to find all the values from numpy record array no1 which are closest to values in rec array no2 (record arrays have different number of values) Lets say no1 has fields: ('electrode', 'i4'), ('no_of_interest_time', 'i4'), ('time',…
Maikia
  • 77
  • 7
2
votes
2 answers

Python numpy recarray: Can one obtain a view into different fields using pointer arithmetic?

I have a numpy structured array of the following form: x = np.array([(1,2,3)]*2, [('t', np.int16), ('x', np.int8), ('y', np.int8)]) I now want to generate views into this array that team up 't' with either 'x' or 'y'. The usual syntax creates a…
Stefan
  • 4,380
  • 2
  • 30
  • 33
1
vote
1 answer

rec2csv exporting with a blank line between rows

I'm trying to export a a recarray to csv file with rec2csv so I can retrieve it later with csv2rec. The problem is that the rec2csv is exporting with a blank line between each rows, so csv2rec cannot read it later. How can I fix this problem with…
catun
  • 11
  • 2
1
vote
1 answer

Join Recarrays by attributes in Python

I am trying to join recarrys in python such that the same value joins to many elements. The following code works when it is a 1:1 ratio, but when I am trying to do many:1, it only joins one instance: import numpy as np import matplotlib # First…
mike
  • 22,931
  • 31
  • 77
  • 100
1
vote
2 answers

How to create nested rec arrays

Given the following arrays: name = np.array(['a', 'b', 'c']) val = np.array([0.4, 0.5, 0.6]) alt = np.array([1.1, 2.1, 3.1]) b = np.array([17.2]) How can I combine them into a recarray (or structured array, same thing) that looks like this: [('a',…
a11
  • 3,122
  • 4
  • 27
  • 66
1
vote
1 answer

Select records of specific data type from numpy recarray

I have a numpy recarray, that has records of different data types or dtypes. import numpy as np a = np.array([1,2,3,4], dtype=int) b = np.array([6,6,6,6], dtype=int) c = np.array(['p', 'q', 'r', 's'], dtype=object) d = np.array(['a', 'b', 'c', 'd'],…
user3046211
  • 466
  • 2
  • 13
1
vote
1 answer

handling None values in conversion to numpy recarray

Is there a graceful way of handling None values in a conversion of a list of tuples to a numpy recarray using the single call to np.rec.fromrecords? Assuming I know what I want the missing value to be (e.g. -1 for integers), how do I catch and…
grovduck
  • 406
  • 5
  • 13
1
vote
1 answer

3D numpy recarray

# pre-allocate data cube cube = np.empty((len(time_ix), len(data_ix), len(id_ix))) cube[:] = np.NaN # filling of cube tix=3 idx=5 data = cube[tix,:,idx] Data is describing the values of 20 columns roughly at that day for that id I am creating a…
Guido
  • 441
  • 3
  • 22
1
vote
0 answers

edit specific column of recarray

I have a table in FITS format that I have to edit. This is a sample of the data in Python: data = FITS_rec([( 0, -1, -1., -540., -1.93287335e-18, -0.14582774, -1., -26.5, 12.12002624, 4), ( 1, -1, -1., -539., -2.19318337e-18,…
1
vote
1 answer

masked arrays in numpy error

I input a file using genfromtxt and some of the values are missing so I generate a masked array. When I try to index some of the values of the records of the masked array I get an error which I cannot figure out. Any help would be highly…
Alex
  • 19,533
  • 37
  • 126
  • 195
1
vote
2 answers

numpy: creating recarray fast with different column types

I am trying to create a recarray from a series of numpy arrays with column names and mixed variable types. The following works but is slow: import numpy as np a = np.array([1,2,3,4], dtype=np.int) b = np.array([6,6,6,6], dtype=np.int) …
K.Doe
  • 11
  • 1
1
vote
1 answer

FITS_rec and selection of data: masking instead of "true" filtering?

Probably a duplicate to Ashley's post (but I can't comment -yet ;) ). I have the same issue when trying to add a column to a sub-selection/sample of my initial FITS_rec (based on numpy's recarray); all the rows reappear (AND the filling of this new…
erez
  • 11
  • 1
1
vote
1 answer

Change how structured arrays and recarrays are printed

Numpy summarizes large arrays, which is convenient when working in an interactive session. Unfortunately, structured arrays and recarrays are not summarized very well by default. Is there a way to change this? By default, the full array is…
user2699
  • 2,927
  • 14
  • 31
1
vote
1 answer

numpy recarray from CSV dtype has many columns but shape says just one row, why is that?

My CSV has a mix of strings and numeric columns. nump.recfromcsv accurately inferred them (woo-hoo) giving a dtype of dtype=[('null', 'S7'), ('00', '
djechlin
  • 59,258
  • 35
  • 162
  • 290
1
vote
1 answer

Get a recarray view of an ndarray (which may also be a view)

I'm trying to get a view of 2D ndarray as a record or structured array without copying. This seems to work fine if a owns it data >>> a = np.array([[ 1, 391, 14, 26], [ 17, 371, 15, 30], [641, 340, 4, 7]]) >>> b…
toes
  • 603
  • 6
  • 13