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

Numpy recarray functions throw TypeError: cannot perform reduce with flexible type

I would like to work with numpy.recarrays as described here: numpy.recarray I construct the numpy.recarray like described and want to execute simple .max(),.sum() methods: a = np.recarray((2,), dtype=[('x', int), ('y', float), ('z',…
0
votes
1 answer

ufunc (min, max, mean, etc) on structured (record) arrays with different dtype

I am working in Python(3.8) with numpy(1.20.3) and trying to perform simple functions on a structured array having different data types. def test_large_record(): x = numpy.array([0.0, 0.2, 0.3], dtype=numpy.float) x_2 = numpy.array([0.01,…
Dan
  • 13
  • 1
  • 5
0
votes
1 answer

Extremely slow on np.recarray assignment

I'm storing ticks with ndarray, each tick has a utc_timestamp[str] as index, tick price/vols as values. Thus I have an array of 2 different dtypes(str and float). This this the way I store it as a np.recarray data = np.recarray((100,),…
aEgoist
  • 31
  • 3
0
votes
1 answer

Add array values to numpy recarray where identifier matches with other array

I am trying to assign values from one recarray (in_arr) into another (out_arr) based on an identifier string in one of the columns. To assign the values correctly, the strings in id must match. Some constraints: the number of elements in in_arr can…
Nyps
  • 831
  • 1
  • 14
  • 26
0
votes
1 answer

Numpy recarray from bytes or string

I have a process where I need to convert a numpy recarray to bytes, and after that reconstruct the recarray from the bytes. However, I am not sure how to do recover the array from bytes. Does anyone know how could I do it? Example code: import numpy…
Daniel Lima
  • 925
  • 1
  • 8
  • 22
0
votes
1 answer

getting recarray into postgres using psycopg2

Just would like to get a quick idea on the best, meaning least coding, way to get lots of data in recarray into postgres using psycopg2. I have seen some stuff using cast but really I thought it would be strait forward and I could find something…
user531525
  • 77
  • 1
  • 1
  • 8
0
votes
1 answer

Convert a string column in a NumPy record array to uppercase

I create a numpy record array (recarray) as follows: import numpy as np recs = [('Bill', '31', 260.0), ('Fred', 15, '145.0')] r = np.rec.fromrecords(recs, names = 'name, age, weight') Now I want to alter the column r['name'] so that the values are…
matthiash
  • 3,105
  • 3
  • 23
  • 34
0
votes
1 answer

How to iterare over recarray rows?

The default recarray iterator seems to be going over columns. Is there a counterpart to pandas’es iterrows/itertuples that iterate row views?
Roman Shapovalov
  • 2,785
  • 1
  • 25
  • 30
0
votes
1 answer

is ndarray faster than recarray access?

I was able to copy my recarray data to a ndarray, do some calculations and return the ndarray with updated values. Then, I discovered the append_fields() capability in numpy.lib.recfunctions, and thought it would be a lot smarter to simply append…
kcw78
  • 7,131
  • 3
  • 12
  • 44
0
votes
1 answer

recarray with lists: how to reference first element in list

I want to copy contents of a few fields in a record array into a ndarray (both type float64). I know how to do this when the recarray data has a single value in each field: my_ndarray[:,0]=my_recarray['X'] #(for field 'X') Now I have a recarray…
kcw78
  • 7,131
  • 3
  • 12
  • 44
0
votes
1 answer

numpy recarray minimum differences

I have a numpy recarray I want to find record where difference of 1st element and last element of record is maximum. can someone suggest a way to do this.
user424060
  • 1,545
  • 3
  • 20
  • 29
0
votes
1 answer

How to find the `base` of a record array

How is base determined for record arrays? The docs seem to describe the same behavior as regular arrays, but that's not what it is. Here's a simple array, and a record array created from it. >>> arr = np.zeros(10, dtype=[('a', float), ('b', int),…
user2699
  • 2,927
  • 14
  • 31
0
votes
1 answer

numpy structured arrays: help understanding output

I am trying to learn how to use numpy's structured arrays. Specifically, I was trying to add information to more than one field at a time. I tried: import numpy as np numrec = np.zeros(8, dtype=[('col0', 'int16'), ('col1', 'int16'), …
Curious2learn
  • 31,692
  • 43
  • 108
  • 125
0
votes
1 answer

Frequency count using itertools.groupby() with recarray

The code goes something like this: >>>data = pd.DataFrame({'P': ['p1', 'p1', 'p2'], 'Q': ['q1', 'q2', 'q1'], 'R': ['r1', 'r1', 'r2']}) >>>data P Q R 0 p1 q1 r1 1 p1 q2 r1 2 p2 q1…
geedee
  • 45
  • 7
0
votes
1 answer

Counting frequency of values in recarray of object datatype

Here's my input: data = np.array ([( 'a1' , np.NaN , 'a2' ), ( 'a1' , 'b2' , 'b1' ), ( 'c1' , 'c1' , np.NaN )], dtype = [( 'A' , object ), ( 'B' , object ), …
geedee
  • 45
  • 7