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
3
votes
4 answers

Convert structured array with various numeric data types to regular array

Suppose I have a NumPy structured array with various numeric datatypes. As a basic example, my_data = np.array( [(17, 182.1), (19, 175.6)], dtype='i2,f4') How can I cast this into a regular NumPy array of floats? From this answer, I know I…
Garrett
  • 4,007
  • 2
  • 41
  • 59
3
votes
1 answer

Numpy structured arrays: string type not understood when specifying dtype with a dict

Here's what happens if I initialize a struct array with the same field names and types in different ways: >>> a = np.zeros(2, dtype=[('x','int64'),('y','a')]) >>> a array([(0L, ''), (0L, '')], dtype=[('x', '
Matt
  • 282
  • 3
  • 13
2
votes
1 answer

Numba signature for structured arrays

Numba's documentation does not give any example of signatures for functions that take structured arrays. I have tried several ways, but all were rejected by Numba (and Pylance). import numba as nb import numpy as np PairSpec = [("x", np.float32),…
Valéry
  • 4,574
  • 1
  • 14
  • 25
2
votes
1 answer

How to assign variable length to an array in twincat3

I need to change the length of the array dynamically.Right now the code looks like this: VAR arrData : ARRAY[1..200] OF INT; length : INT := 200; END_VAR The size of the array depends on the length variable.Here the value of length variable…
2
votes
4 answers

Flatten nested fields of a numpy structured array

I have many millions of rows of structured arrays with a couple of different schemas in my dataset, some with multiple nested columns, but none with deeply nested columns (i.e. there are no nested columns other than the very first level of their…
ofo
  • 1,160
  • 10
  • 21
2
votes
2 answers

How to get a list of dtypes from a numpy structured array?

How can I get a list of dtypes from a numpy structured array? Create example structured array: arr = np.array([[1.0, 2.0],[3.0, 4.0]]) dt = {'names':['ID', 'Ring'], 'formats':[np.double, np.double]} arr.dtype = dt >>> arr array([[(1., 2.)], …
Kermit
  • 4,922
  • 4
  • 42
  • 74
2
votes
2 answers

Referring to a field in a numpy structured array is the same size as the entire array

Issue I have a numpy structured array and I want to take two small fields. When I do, I get an item that is as large as the original Example >>> A = np.zeros(100, dtype=[('f',float),('x',float,2),('large',float,500000)]) >>> A.itemsize 4000024 >>>…
jmlarson
  • 837
  • 8
  • 31
2
votes
2 answers

Appropriate formatting of NumPy dtypes for arrays within Structured Arrays

I am trying to create a numpy structured array but I can't figure out the correct way to format my column titles/column types for arrays within arrays. I keep getting the setting an array element with a sequence message, but I can convert the list…
SomeoneElse
  • 486
  • 1
  • 6
  • 22
2
votes
1 answer

Add and access object-type field of a numpy structured array

I am using numpy 1.16.2. In brief, I am wondering how to add an object-type field to a structured array. The standard way via the recfunctions module throws an error and I suppose there is a reason for this. Therefore, I wonder whether there is…
Samufi
  • 2,465
  • 3
  • 19
  • 43
2
votes
2 answers

How to join numpy structured array with duplicates

R user here, and I'm attempting my first project in Python to take advantage of Numba. I've read that Numba works very well with Numpy but not well with Pandas, so I am attempting to avoid Pandas. My current question actually has nothing to do with…
Frank
  • 21
  • 3
2
votes
1 answer

Array of structs to NumPy structured array: np.ctypeslib.as_array from ndpointer

I'm trying to call to a C function that accept a pointer to pointer and redirect it to a internally-allocated 1D array, something along that line: typedef myStruct { const char* name; int status; } myStruct; int foo(const myStruct** array,…
galah92
  • 3,621
  • 2
  • 29
  • 55
2
votes
1 answer

Grabbing the name of a numpy structured array column when passed as a parameter to a function

When trying to use a numpy.array (a structured numpy array) I know I can pull up a column by doing something like array["col"]. From my understanding, this is because of numpy.dtype.names and the nature of structured arrays. However, when passing…
2
votes
1 answer

Sub-arrays in numpy structured array not c contiguous

I currently try to pack a multitude of arrays to numpy structured arrays. According to the numpy documentation Sub-arrays always have a C-contiguous memory layout. But if I create a structured array with: x = np.zeros((2,), dtype=[('a',…
JE_Muc
  • 5,403
  • 2
  • 26
  • 41
2
votes
2 answers

How to store by columns in a structured numpy array

I have a list of tuples that look like this: >>> y [(0,1,2,3,4,...,10000), ('a', 'b', 'c', 'd', ...), (3.2, 4.1, 9.2, 12., ...), ] etc. y has 7 tuples, where each tuple has 10,000 values. All 10,000 values of a given tuple are the same dtype, and I…
Tingy
  • 35
  • 7
2
votes
0 answers

How to share numpy structured array among python multiprocesses?

I have a numpy structured array whose dtype has mutiple fields with different data type. And I want to update this structured numpy array in my python multiprocesses. And I think I am going to use Pool. What way I can use to share this numpy…
lX-Xl
  • 160
  • 1
  • 6
1 2
3
9 10