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

Working with NumPy structured arrays

I am working with a NumPy structured array with the following structure: ar = np.array([(760., 0), (760.3, 0), (760.5, 0), (280.0, 1), (320.0, 1), (290.0, 1)], dtype=[('foo', 'f4'),('bar', 'i4')]) What is an efficient way of extracting the 'foo'…
0
votes
1 answer

populating a structured array throws "ndarray is not C-contiguous" error

I am working with a structured array defined in this way: scores = np.empty((num_of_imgs, 4), dtype=[('id', 'u4'), ('bestT', 'u8'), ('bestR', 'f8'), ('bestP', 'f8')]) then in a for loop I populate it: scores[i] = [id,…
aretor
  • 2,379
  • 2
  • 22
  • 38
0
votes
3 answers

C programming FILE output of struct array

After running the code with the following inputs, a runtime error occurs: id : 123 name : stackoverflow quantity : 123 price : 123 I need help to solve this. Previously, I put the ampersand/& at: fprintf(fp, "%d %s %d %d\n\n", a.id, a.name,…
Alif Khair
  • 87
  • 1
  • 1
  • 7
0
votes
2 answers

When does advanced indexing on structured masked arrays *really* return a copy?

When I have a structured masked array with boolean indexing, under what conditions do I get a view and when do I get a copy? The documentation says that advanced indexing always returns a copy, but this is not true, since something like X[X>0]=42…
gerrit
  • 24,025
  • 17
  • 97
  • 170
0
votes
2 answers

Remove duplicate values from numpy structured array

I have a structured array v such as import numpy as np v = np.zeros((3,3), [('a1', np.int),('a2', np.int), ('a3', np.int), ('a4', np.int), ('a5', np.int), ('a6', np.int)]) Usually v would be much larger, with the 'a1', ..., 'a6' values…
Luiz Eleno
  • 13
  • 3
0
votes
1 answer

Access line by line to a numpy structured array

I am trying to access to a structured array line by line by iterating on the values of one field of it but even if the value iterate well, the slice of the array doesn't change. Here is my SWE : import numpy as…
Sigmun
  • 1,002
  • 2
  • 12
  • 23
0
votes
1 answer

Getting looped struct data into a file in C

I have a looped struct array that accepts student name and roll number for as many students the user inputs Code: int x; struct studs { char name[50]; char rollno[50]; }student[50]; …
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

NumPy argmax and structured array error: expected a readable buffer object

I got the following error while using NumPy argmax method. Could some one help me to understand what happened: import numpy as np b = np.zeros(1, dtype={'names':['a','b'], 'formats': ['i4']*2}) b.argmax() The error is TypeError: expected a…
Bin Zhou
  • 603
  • 2
  • 10
  • 17
-1
votes
1 answer

How to get copy of structured array selection

I have a structured array with mixed types: dt = np.dtype([('x', np.float64), ('y', np.float64), ('n', np.uint32)]) arr = np.empty(10, dtype=dt) As of numpy 1.16 or so, if I view x and y, I get a view: >>> sub = arr[['x', 'y']] >>>…
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
-1
votes
2 answers

How to copy list of tuples to EXISTING numpy array in shared memory

I have a structured numpy array in shared memory, that's only one "layer" of a higher dimensional array. And I have a list of tuples whose values I want to copy to this (sub) array. I've found how to make a new numpy structured array out of a list…
Jacques de Hooge
  • 6,750
  • 2
  • 28
  • 45
-1
votes
1 answer

How to import from a data file a numpy structured array

i'm trying to create an array which has 5 columns imported from a data file. The 4 of them are floats and the last one string. The data file looks like…
crystal
  • 103
  • 6
-1
votes
2 answers

combine and aggregate data from structured numpy array to another

I've got an empty structured array: id_and_orders_type = np.dtype([('id', 'i4'), ('order_values', 'f4', (100,))]) id_and_orders = np.zeros((10,), dtype=id_and_orders_type) and I've got another structured array with the data to be filled into…
Andrew
  • 67
  • 8
-1
votes
3 answers

PYTHON/NUMPY: Handling structured arrays compared to common numpy-arrays Python2.7

The main reason why I am asking this question is because I do not exactly know how the structured arrays work compared to normal arrays and because I could not find suitable examples online for my case. Further, I am probably filling my structured…
firefly2517
  • 115
  • 2
  • 15
-1
votes
1 answer

How Do I fill in this Structure String Array in vbNET?

Visual studio tells me the variable must be declared even though it already is. I filled in a structured array in a similar way using a loop though the type was an Int. I do not want to use a loop this time just hard code it. Structure Sentence …
Jon Q
  • 63
  • 1
  • 1
  • 7
1 2 3
9
10