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
1
vote
1 answer

How to modify one column of a selected row from a numpy structured array

I am looking for an easy way to modify one field of a numpy structured array of a selected line of it. Here is my SWE : import numpy as np dt=np.dtype([('name',np.unicode,80),('x',np.float),('y',np.float)]) a=np.array(…
Sigmun
  • 1,002
  • 2
  • 12
  • 23
1
vote
2 answers

Filter numpy structured array based on partial match to a list

I have a follow up question on one I posted here. In that question, I sought to sum values in a numpy structured array based on multiple criteria, including matches in a list. @ali_m provided a successful answer to that question: criteriaList =…
1
vote
1 answer

Filter numpy structured array based on multiple values

I have a numpy structured array. : myArray = np.array([(1, 1, 1, u'Zone3', 9.223), (2, 1, 0, u'Zone2', 17.589), (3, 1, 1, u'Zone2', 26.95), (4, 0, 1, u'Zone1', 19.367), (5, 1, 1, u'Zone1', 4.395)], …
1
vote
1 answer

Get a recarray view of an ndarray (which may also be a view)

I'm trying to get a view of 2D ndarray as a record or structured array without copying. This seems to work fine if a owns it data >>> a = np.array([[ 1, 391, 14, 26], [ 17, 371, 15, 30], [641, 340, 4, 7]]) >>> b…
toes
  • 603
  • 6
  • 13
1
vote
2 answers

Shuffling structured array (Record arrays)

How can I shuffle structured array. numpy.random.shuffle does not seem to work. Further is it possible to shuffle only a given field say x in the following example. import numpy as np data = [(1, 2), (3, 4.1), (13, 77), (5, 10), (11, 30)] dtype =…
imsc
  • 7,492
  • 7
  • 47
  • 69
1
vote
3 answers

ndarray to structured_array and float to int

The problem I encounter is that, by using ndarray.view(np.dtype) to get a structured array from a classic ndarray seems to miscompute the float to int conversion. Example talks better: In [12]: B Out[12]: array([[ 1.00000000e+00, …
Touki
  • 833
  • 2
  • 9
  • 20
0
votes
1 answer

Convert a C-generated nested ndarray into a 1D array in numpy, while preserving dtypes

I have a .npy output that I am trying to parse. It is a nested ndarray with attached dtypes. I would like to "unpack" this array and convert it to a nice pandas DataFrame in the end, ideally while preserving the specified dtypes. Here is a chunk of…
0
votes
1 answer

Getting 'unsupported array index type unicode_type' error when selecting a column based on condition in Numba with NumPy structured array

I am trying to select a column of a structured NumPy array. The column to be selected depends on a condition that will be passed to the function. Numba throws the error below when I try to select the column name based on the condition. Otherwise…
D.Manasreh
  • 900
  • 1
  • 5
  • 9
0
votes
1 answer

Column stacking nested numpy structure array, help getting dims right

I'm trying to create a nested record array, but I am having trouble with the dimensions. I tried following the example at how to set dtype for nested numpy ndarray?, but I am misunderstanding something. Below is an MRE. The arrays are generated in a…
a11
  • 3,122
  • 4
  • 27
  • 66
0
votes
0 answers

What is the correct format and syntax for reading data with subarrays into numpy structured array?

I'm trying to use np.genfromtxt to read in a text file into a variety of data types, some of which are ideally sub arrays, however I can't seem to find the right code or input format for this, I've managed to get numpy to complain I both have too…
James B
  • 1
  • 1
0
votes
0 answers

Using arithmetic on numpy structured array elements?

Lets say that I have a structured numpy array like this: x = np.array([(1, 1.5), (2, 5.21)], dtype=[('foo', 'i4'), ('bar', 'f8')]) What I want to do is be able to add and scalar-multiply these structured array elements together much like you would…
0
votes
1 answer

numpy structured array inconsistency

I'm writing a library that uses NumPy arrays and I have a scalar operation I would like to perform on any dtype. This works fine for most structured arrays, however I run into a problem when creating structured arrays with multiple dimensions for…
Eric J
  • 131
  • 1
  • 1
0
votes
1 answer

How to return a 1D structured array (mixed types) from a numba-JIT-compiled function?

I am trying to use numba to JIT-compile a function in no-Python-mode that has multiple return values, e.g. def foo(ii: int) -> tuple[int, int, float, float, int]: return 1 + ii, 2 + ii, 3.0 + ii, 4.0 + ii, 5 + ii The closest I can think of is…
s-m-e
  • 3,433
  • 2
  • 34
  • 71
0
votes
0 answers

TF-Agent: Numpy Structured Arrays with differnt dtypes in ArraySpec

My agent needs to set an action based on a position which can be represented as a integer value (e.g. np.int32). This integer value will then be used for indexing the certain array. Furthermore, a float number will be assigned to this position.…
Ling
  • 449
  • 6
  • 21
0
votes
0 answers

Numpy's Future Warning for Comparison of Ndarrays when Trying to Create a Numpy Structured Array

When trying to create a numpy structured array with the code below: import numpy as np z = np.zeros([3,3], dtype=[("x",float)]) print(z) I'm getting two Future Warnings: sys:1: FutureWarning: elementwise comparison failed; returning scalar instead,…
Gustavo Mirapalheta
  • 931
  • 2
  • 11
  • 25