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

python structured/recarray type conversion behaviour

I'm confused by the behaviour of type conversion when constructing a structured/recarray: This simple example takes in numerical fields but defines the type as string: data = [(1.0, 2), (3.0, 4)] np.array(data, dtype=[('x', str), ('y',…
retrocookie
  • 319
  • 2
  • 10
5
votes
2 answers

How to hstack arrays of numpy records?

[An earlier version of this post had the inaccurate title "How to add one column to an array of numpy records?" The question asked in that earlier title has already been partially answered, but this answer is not quite what the body of that earlier…
kjo
  • 33,683
  • 52
  • 148
  • 265
4
votes
3 answers

How to change the dtype of a ndarray to custom one in numpy?

I made a dtype that is: mytype = np.dtype([('a',np.uint8), ('b',np.uint8), ('c',np.uint8)]) so the array using this dtype: test1 = np.zeros(3, dtype=mytype) test1 is: array([(0, 0, 0), (0, 0, 0), (0, 0, 0)], dtype=[('a', '|u1'), ('b',…
Clippit
  • 856
  • 1
  • 9
  • 20
4
votes
2 answers

Add a 2d array(field) to a numpy recarray

I want to add a 2D field to an existing recarray, using numpy.lib.recfunctions.append_fields. Let's say I made a recarray. > arr = np.recarray(10, [("afield", " arr.dtype dtype((numpy.record, [('afield', '
Hoseung Choi
  • 1,017
  • 2
  • 12
  • 20
4
votes
1 answer

Converting (part of) a numpy recarray into a 2d array?

We've got a set of recarrays of data for individual days - the first attribute is a timestamp and the rest are values. Several of these: ts a b c 2010-08-06 08:00, 1.2, 3.4, 5.6 2010-08-06 08:05, 1.2, 3.4, 5.6 2010-08-06…
babbageclunk
  • 8,523
  • 1
  • 33
  • 37
4
votes
2 answers

How to output dtype to a list or Dict

I just want to get a list or dict from dtype out of a numpy array. Thought it would be a easy but it is not itterable. I looked other places but could not find answer. jn is a recarray [OrderedDict(row) for i, row in…
user531525
  • 77
  • 1
  • 1
  • 8
4
votes
4 answers

Numpy Mean Structured Array

Suppose that I have a structured array of students (strings) and test scores (ints), where each entry is the score that a specific student received on a specific test. Each student has multiple entries in this array, naturally. Example import…
Jeremy
  • 225
  • 2
  • 11
3
votes
1 answer

numpy recarray copy retains dtype reference?

I am trying to copy a recarray and change the names of the fields/records in the new array. However, this modifies the names of the original array (the values are not unlinked, however). Example: import numpy as np import copy define original…
hatmatrix
  • 42,883
  • 45
  • 137
  • 231
3
votes
2 answers

numpy: Replacing values in a recarray

I'm pretty new to numpy, and I'm trying to replace a value in a recarray. So I have this array: import numpy as np d = [('1', ''),('4', '5'),('7', '8')] a = np.array(d, dtype=[('first', 'a5'), ('second', 'a5')]) I would like to do something like…
reisner
  • 242
  • 3
  • 14
3
votes
1 answer

numpy recarray append_fields: can't append numpy array of datetimes

I have a recarray containing various fields and I want to append an array of datetime objects on to it. However, it seems like the append_fields function in numpy.lib.recfunctions won't let me add an array of objects. Here's some example…
ccbunney
  • 2,282
  • 4
  • 26
  • 42
3
votes
1 answer

How do I access field #k of a numpy recarray?

I can create a recarray and access its members by name: import numpy as np n = 20 x = np.recarray((n,), dtype=[('x',int),('y',float),('label',object)]) x.x[:] = range(n) x.y[:] = np.arange(n)*0.08 x.label[:] = ['%d bottles of beer on the wall' % i…
Jason S
  • 184,598
  • 164
  • 608
  • 970
3
votes
3 answers

Combining two record arrays

I have two Numpy record arrays that have exactly the same fields. What is the easiest way to combine them into one (i.e. append one table on to the other)?
astrofrog
  • 32,883
  • 32
  • 90
  • 131
3
votes
0 answers

numpy.concatenate of two recarrays leads to transposed shape?

Suppose I have two numpy arrays x1 and x2 with the same dtype but different shape:x1.dtype = dtype([('fmv', '
Joel Vroom
  • 1,611
  • 1
  • 16
  • 30
2
votes
1 answer

numpy: query a data from masked record?

I have mask record like this In [41]: x Out[41]: masked_records( CHR : [12 12 12 ..., 12 12 12] SNP : [rs4980929 rs4980929 rs4980929 ..., rs7975069 rs7975069 rs7975069] A1 : [C C C ..., T T T] A2 : [T T T ..., C C C] …
Tg.
  • 5,608
  • 7
  • 39
  • 52
2
votes
0 answers

numpy recfunctions join_by bug

There seems to be a problem with the join_by function in numpy.lib.recfunctions when doing an outer join on multiple keys. The matplotlib.mlab function works correctly. The recfunctions version seems to mix/match some of the keys (I had two keys:…
Alex
  • 19,533
  • 37
  • 126
  • 195