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

Removing rows with nan values in recarrays of object datatype

Here is my input: data = np.array ( [ ( 'a2', 'b1', 'c1' ), ( 'a1', 'b1', 'c1' ), ( 'a2', np.NaN, 'c2' ) ], dtype = [ ( 'A', 'O' ), ( 'B', 'O' ), ( 'C', 'O' ) ] ) . view ( np.recarray) I want this as the output: rec.array ( [ ( 'a2', 'b1', 'c1' ),…
geedee
  • 45
  • 7
0
votes
1 answer

Inheriting from numpy.recarray, __unicode__ issue

I have made a subclass of a numpy.recarray. The purpose of the class is to provide pretty printing for record arrays while maintaining the record array functionality. Here is the code: import numpy as np import re class TableView(np.recarray): …
snowleopard
  • 717
  • 8
  • 19
0
votes
1 answer

Efficient GROUP BY query on numpy recarray

I have a dataset of product purchases logs with 6 columns: purchase_date, user_address, user_id, product_id, brand_id, retailer_id. All contain integers, except user_address which is a string. I need to get the top 5 brands selling the most items…
0
votes
1 answer

Create a new array from numpy array based on the conditions from a list

Suppose that I have an array defined by: data = np.array([('a1v1', 'a2v1', 'a3v1', 'a4v1', 'a5v1'), ('a1v1', 'a2v1', 'a3v1', 'a4v2', 'a5v1'), ('a1v3', 'a2v1', 'a3v1', 'a4v1', 'a5v2'), ('a1v2', 'a2v2', 'a3v1', 'a4v1', 'a5v2'), …
riza
  • 16,274
  • 7
  • 29
  • 29
0
votes
1 answer

How to circumvent the restriction on field names?

If I define a recarray r with a field called data as follows import numpy r = numpy.zeros( 1, numpy.dtype([('data', 'f8')]) ).view(numpy.recarray ) the data field will refer to some internal recarray buffer rather than a floating point number.…
Andrey Sokolov
  • 394
  • 1
  • 4
  • 12
0
votes
1 answer

How to change a structured array item size in Numpy?

I am trying to change the size of an item in a Numpy structured array. The following code triggered an error saying the array can not be broadcasted because of the size difference. Is there a way to accomplish my goal short of making a new…
Hans
  • 1,269
  • 3
  • 19
  • 38
0
votes
1 answer

comparing rows in recarray

I have a csv file which looks like…
ukg
  • 11
  • 2
0
votes
1 answer

reassigning expanded recarray field

I am loading file data into a numpy recarray and subsequently filling in known gaps with NaNs. However, I can not find a way to increase the size of the field in the recarray in order to reassign the array with filled gaps. An example of my…
RJCL
  • 357
  • 3
  • 14
0
votes
1 answer

Split numpy recarray based on value in one column

my real data has some 10000+ items. I have a complicated numpy record array of a format roughly like: a = (((1., 2., 3.), 4., 'metadata1'), ((1., 3., 5.), 5., 'metadata1'), ((1., 2., 4.), 5., 'metadata2'), ((1., 2., 5.), 5.,…
troy.unrau
  • 1,142
  • 2
  • 12
  • 26
0
votes
2 answers

Is it possible to mmap a recarray in python 2.7?

I have a large global recarray totaling 30GBs of data in a programme running via qsub on a cluster with 256GBs of RAM. I am currently the only user on this cluster so there are no conflicts with the allocation of RAM. When looping over this recarray…
Tom Smith
  • 371
  • 2
  • 3
  • 14
0
votes
3 answers

Index datetime in numpy array

I have a numpy array roughly like so: data array([(datetime.datetime(2009, 1, 6, 2, 30), 17924.0, 0.0),.... (datetime.datetime(2009, 1, 29, 16, 30), 35249.2, 521.25], dtype=[('timestamp', '|O4'), ('x1', '
djmac
  • 827
  • 5
  • 11
  • 27
0
votes
0 answers

python numpy recarray stacking

How can I stack or join numpy recarrays without getting errors like: self.data = numpy.lib.recfunctions.stack_arrays((self.data, data))# , asrecarray=True) # works File "/usr/local/lib/python3.2/site-packages/numpy/lib/recfunctions.py", line…
mathtick
  • 6,487
  • 13
  • 56
  • 101
0
votes
1 answer

python numpy recarray join

Is there no "join" function in numpy recarrays? I see matplotlib has something and there is a concatenate but this is not a solution. I want a fast join in numpy/scipy or understand why it is not there.
mathtick
  • 6,487
  • 13
  • 56
  • 101
1 2 3 4 5 6
7