Questions tagged [structured-array]

Numpy structured arrays (aka "Record arrays") allow for inhomogenous datatypes (structs/records) to be stored in a single numpy array

Numpy structured arrays (aka "Record arrays") allow for inhomogenous datatypes (structs/records) to be stored in a single numpy array.

150 questions
2
votes
1 answer

How to write to single field in structured array without getting warning

I am trying to normalize all data contained in different fields of my structured array if the field contains floats. However, even though I am looping through each field one-by-one I am receiving a warning. for idt, dt in…
Nyps
  • 831
  • 1
  • 14
  • 26
2
votes
1 answer

NumPy recfunctions join_by TypeError

I encounter a TypeError when I attempt to join a 'uint16' field to a structured array in NumPy 1.11 or 1.12 (Python 3.5). import numpy as np from numpy.lib import recfunctions as rfn foo = np.array([(1,)], dtype=[('key', int)]) bar =…
eatcrayons
  • 1,542
  • 15
  • 17
2
votes
1 answer

numpy array as datatype in a structured array?

I was wondering if it is possible to have a numpy.array as a datatype in a structured array. This is the idea: import numpy raw_data = [(1, numpy.array([1,2,3])), (2, numpy.array([4,5,6])), (3, numpy.array([7,8,9]))] data…
mommermi
  • 982
  • 10
  • 18
2
votes
1 answer

Filling empty DataFrame with numpy structured array

I created an empty DataFrame by doing the following: In [581]: df=pd.DataFrame(np.empty(8,dtype=([('f0', '
snowleopard
  • 717
  • 8
  • 19
2
votes
0 answers

Error when accessing element in structured array

1I am currently using a structured array to save some measurements from a sensor. The array (named "data") is of the dimension 2000x3 with the three fields: "samples", "timestamp" and "labels", where samples is a vector of 6 elements. For example,…
BStadlbauer
  • 1,287
  • 6
  • 18
2
votes
2 answers

Create a Record array from a list of dictionaries

Given a list of dictionaries as follows: dict_data = [ {'name': 'r1', 'interval': [1800.0, 1900.0], 'bool_condition': [True, False]}, {'name': 'r2', 'interval': [1600.0, 1500.0], 'bool_condition': [False]}, {'name': 'r3', 'interval':…
saloua
  • 2,433
  • 4
  • 27
  • 37
2
votes
3 answers

kwarg-splatting a numpy array

How can I write a wrapper class that makes this work? def foo(a, b): print a data = np.empty(20, dtype=[('a', np.float32), ('b', np.float32)]) data = my_magic_ndarray_subclass(data) foo(**data[0]) Some more background: I had a pair of…
Eric
  • 95,302
  • 53
  • 242
  • 374
2
votes
1 answer

Shape of a structured array in numpy

I am trying to preallocate an empty array and at the same time defining the data type with a size of 19x5 using the following code: import numpy as np arr=np.empty((19,5),dtype=[('a','|S1'),('b', 'f4'),('c', 'i'),('d', 'f4'),('e', 'f4')]) The…
Fourier
  • 2,795
  • 3
  • 25
  • 39
2
votes
1 answer

Constructing np.array with overlapping fields in dtype

I have a dtype as follows: pose_dtype = np.dtype([('x', np.float64), ('y', np.float64), ('theta', np.float64)]) Right now, I can write: pose = np.array((1, 2, np.pi), dtype=pose_dtype) I'd like to add an xy field to make this easier to work with.…
Eric
  • 95,302
  • 53
  • 242
  • 374
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

Is the mask of a structured array supposed to be structured itself?

I was looking into numpy issue 2972 and several related problems. It turns out that all those problems are related to the situation where the array itself is structured, but its mask is not: In [38]: R = numpy.zeros(10, dtype=[("A", "
gerrit
  • 24,025
  • 17
  • 97
  • 170
2
votes
1 answer

What is the syntax to instantiate a structured dtype in numpy?

If I have a dtype like foo = dtype([('chrom1', '
traeki
  • 33
  • 6
1
vote
1 answer

Assigning issue with numpy structured arrays

I was trying this simple line of assigning codes to a structured array in numpy, I am not quiet sure, but something wrong happens when I assign a matrix to a sub_array in a structured array I created as follows: new_type = np.dtype('a3,(2,2)u2') x =…
JustInTime
  • 2,716
  • 5
  • 22
  • 25
1
vote
1 answer

Nested structured array to pandas dataframe with new column names

How can I convert/explode a nested numpy structured array into a pandas dataframe, while keeping the headers from the nested arrays? Using Python 3.8.3, numpy 1.18.5, pandas 1.3.4. Example structured array: I am given a nested numpy structured array…
a11
  • 3,122
  • 4
  • 27
  • 66
1
vote
1 answer

How to do columnwise operations with Numpy structured arrays?

This shows the problem nicely: import numpy as np a_type = np.dtype([("x", int), ("y", float)]) a_list = [] for i in range(0, 8, 2): entry = np.zeros((1,), dtype=a_type) entry["x"][0] = i entry["y"][0] = i + 1.0 …
Andreas Schuldei
  • 343
  • 1
  • 15