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
2 answers

numpy recarray indexing based on intersection with external array

I'm trying to subset the records in a numpy.recarray based on the common values between one of the recarrays fields and an external array. For example, a = np.array([(10, 'Bob', 145.7), (20, 'Sue', 112.3), (10, 'Jim', 130.5)], dtype=[('id',…
grovduck
  • 406
  • 5
  • 13
2
votes
2 answers

Copy a sub-recarray in stable NumPy

Suppose I have data in a numpy.recarray, and I want to extract some of its columns. I want this to be an effective copy since data may be huge (I don't want to copy everything) but I will likely change these features without wanting to change data…
Thrastylon
  • 853
  • 7
  • 20
2
votes
2 answers

Selecting columns from numpy recarray

I have an object from type numpy.core.records.recarray. I want to use it effectively as pandas dataframe. More precisely, I want to use a subset of its columns in order to obtain a new recarray, the same way you would do…
Baron Yugovich
  • 3,843
  • 12
  • 48
  • 76
2
votes
2 answers

How to aggregate NumPy record array (sum, min, max, etc.)?

Consider a simple record array structure: import numpy as np ijv_dtype = [ ('I', 'i'), ('J', 'i'), ('v', 'd'), ] ijv = np.array([ (0, 0, 3.3), (0, 1, 1.1), (0, 1, 4.4), (1, 1, 2.2), ], ijv_dtype) print(ijv) # [(0, 0,…
Mike T
  • 41,085
  • 18
  • 152
  • 203
2
votes
1 answer

Fortran ordered (column-major) numpy structured array possible?

I am looking for a way to more efficiently assign column of a numpy structured array. Example: my_col = fn_returning_1D_array(...) executes more than two times faster on my machine than the same assignment to the column of a structured array: test…
ARF
  • 7,420
  • 8
  • 45
  • 72
2
votes
1 answer

How to convert a subset of numpy recarray to continuous array?

I have a recarray that comes from reading a csv file. I am interested in converting a subset of columns to a continuous float array. I'd like to avoid converting them to list or stacking them one by one. I tried the suggestions in…
lib
  • 2,918
  • 3
  • 27
  • 53
2
votes
1 answer

Create view to recarray subclass

I want to subclass numpy recarrays and being able to create views from that class. For example: _Theta = np.dtype([('v', '
eaponte
  • 409
  • 5
  • 15
2
votes
1 answer

Concatenating numpy record arrays with same fields in different order

I have two ndarrays with "compatible" but non-identical dtypes, like this: In [22]: A = numpy.empty(shape=(5), dtype=[("A", "f4"), ("B", "f4")]) In [23]: B = numpy.empty(shape=(5), dtype=[("B", "f4"), ("A", "f4")]) In [24]: numpy.concatenate((A,…
gerrit
  • 24,025
  • 17
  • 97
  • 170
2
votes
1 answer

Removing a row in a numpy recarray

Is there a convenient way to delete a row containing some value in a recarray? Say I have the following array, a=numpy.array([(1.0, 2.0, 3.0), (4.0, 5.0, 10.0),(1.0,10.0,4.0)], dtype=[('A', '
Alex
  • 302
  • 3
  • 16
2
votes
1 answer

python tensors with named field access

I would like to use in Python something akin to -- or better than -- R arrays. R arrays are tensor-like objects with a dimnames attribute, which allows to straightforwardly allows to subset tensors based on names (strings). In numpy recarrays allow…
gappy
  • 10,095
  • 14
  • 54
  • 73
2
votes
1 answer

subclassed empty numpy recarray losing its type and added attributes in numpy 1.8

I am trying to implement a subclass of a numpy recarray (recsub) and assign instances of it to an ndarray of dtype 'object' (ndarr). It works well, but i have a problem when the subclassed recarray is instantiated with an empty array. This is the…
mher
  • 369
  • 3
  • 7
2
votes
2 answers

numpy masked array behaves differently when one dtype is an object

say that I have the following two masked arrays declarations: arr1 = ma.array([(1,2,"hello"),(10,20,"world!")],dtype=[("p1",int),("p2",float),("p3",object)]) arr1.mask["p1"][0] = True arr1.mask["p2"][1] = True arr2 =…
Eurydice
  • 8,001
  • 4
  • 24
  • 37
2
votes
1 answer

how to set dtype for nested numpy ndarray?

I am working on the following data structure, from which I am trying to create a ndarray contains all the data: instrument filter response ----------------------------------------------------- spire …
Jerry Ma
  • 511
  • 4
  • 15
2
votes
1 answer

About the docs of recarray's multiple fields indexing

In the section Accessing multiple fields at once of numpy docs, says that: Notice that the fields are always returned in the same order regardless of the sequence they are asked for. The docs also give a example as following: >>> x =…
Eastsun
  • 18,526
  • 6
  • 57
  • 81
2
votes
1 answer

Change dtype of recarray column for object type

I have a csv file where two columns (v3 and v7) are blank for all observations: v1,v2,v3,v4,v5,v6,v7 GNB,1980,,20,-1.168689,0.4619077, GNB,1981,20,-1.185176,0.4619077, I am reading this into python (epd-7.0-2) using the csv2rec function: from pylab…
mike
  • 22,931
  • 31
  • 77
  • 100