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

TypeError when appending fields to a structured array of size ONE

I'm getting a run-time error when trying to append field(s) to a structured array of size ONE. I've written a simple example below: import numpy as np import numpy.lib.recfunctions as rcfuncs dtype_ = np.dtype( { 'names':…
stackoverflower
  • 301
  • 4
  • 14
4
votes
2 answers

comparing numpy structured arrays

The quick problem I would like to be able to compare specific dtype fields from two numpy structured arrays that are guaranteed to have the same dtype. I would like to do this in a way that allows the fields we are comparing to be different each…
Andrew
  • 693
  • 6
  • 19
4
votes
1 answer

slice a numpy structured 1-d array to get part of a record

I have a numpy 1-D structured array and I want to get just a part of one record out. I was trying to figure out how to slice this type of request. Here is my code: summary_stat_list = ['mean', 'variance', 'median', 'kurtosis',…
krishnab
  • 9,270
  • 12
  • 66
  • 123
4
votes
1 answer

numpy fromfile and structured arrays

I'm trying to use numpy.fromfile to read a structured array (file header) by passing in a user defined data-type. For some reason, my structured array elements are coming back as 2-d Arrays instead of flat 1D arrays: headerfmt='20i,20f,a80' dt =…
mgilson
  • 300,191
  • 65
  • 633
  • 696
3
votes
2 answers

How to get field of nested numpy structured array (advanced indexing)

I have a complex nested structured array (often used as a recarray). Its simplified for this example, but in the real case there are multiple levels. c = [('x','f8'),('y','f8')] A = [('data_string','|S20'),('data_val', c, 2)] zeros = np.zeros(1,…
001001
  • 530
  • 1
  • 4
  • 13
3
votes
1 answer

How can I use Numba "@vectorize" ufunc with a structured Numpy array?

I'm unable to get a vectorized ufunc to run. Regular @njit works fine and the @vectorize documentation suggests that the vectorize decorators are the same as njit. I'm running on Windows 10, if that makes a difference The demo program is as…
1472580
  • 163
  • 1
  • 8
3
votes
1 answer

Convert a slice of a structured array to regular NumPy array in NumPy 1.14

Note 1: None of the answers given to this question work in my case. Note 2: The solution must work in NumPy 1.14. Assume I have the following structured array: arr = np.array([(105.0, 34.0, 145.0, 217.0)], dtype=[('a', 'f4'), ('b', 'f4'), ('c',…
Alex
  • 3,316
  • 4
  • 26
  • 52
3
votes
2 answers

Converting numpy structured array subset to numpy array without copy

Suppose I have the following numpy structured array: In [250]: x Out[250]: array([(22, 2, -1000000000, 2000), (22, 2, 400, 2000), (22, 2, 804846, 2000), (44, 2, 800, 4000), (55, 5, 900, 5000), (55, 5, 1000, 5000), (55, 5, 8900, 5000),…
snowleopard
  • 717
  • 8
  • 19
3
votes
5 answers

Structured array in Java

I am trying to migrate my Objective C code into Java to learn this programming language. I would like to "convert" the following ObjectiveC structure into Java, but I couldn't find the equivalent Java structure: g_vo2MaxFemales = @[ …
3
votes
2 answers

Read/Write NumPy Structured Array very slow, linear in size slow

To my surprise I have discovered, that reading from and writing to NumPy Structured arrays seems to be linear in size of the array. As this seems very wrong, I would like to know, if I do something wrong here or if there might be a bug. Here is…
user2532323
  • 237
  • 1
  • 2
  • 7
3
votes
1 answer

Surface plotting structured array error

I've been trying to represent this structured array in a 3d plot in hopes of later mapping it. import matplotlib.pyplot as plt import numpy as np import os from mpl_toolkits.mplot3d import Axes3D path = '/users/username/Desktop/untitled…
iron2man
  • 1,787
  • 5
  • 27
  • 39
3
votes
1 answer

How do I fill multiple named fields using structured data

I would like to take the information from some fields and just write them into another variable using a list. import numpy as np var1 = np.array([(1,2,3,4),(11,22,33,44),(111,222,333,444)], dtype=([('field1',…
Xesc
  • 31
  • 2
3
votes
1 answer

Counting number of unique values in subset of sorted array

I have two numpy arrays, users and dat. For each user in users I need to find the data related to the user in dat and count the number of unique values. I need to process a case where len(users)=200000 and len(dat)=2800000. Currently I am not…
pir
  • 5,513
  • 12
  • 63
  • 101
3
votes
2 answers

Two-Dimensional structured array

I am trying to construct a structured array in Python that can be accessed by the names of the columns and rows. Is this possible with the structured array method of numpy? Example: My array should have roughly this form: My_array = A B C …
swot
  • 278
  • 1
  • 3
  • 10
3
votes
1 answer

Why does an assignment to a boolean indexed structured array depend on index ordering?

I have seen a phenomenon recently in working with structured numpy arrays that doesn't make sense. I am hoping someone can help me understand what is going on. I have provided a minimal working example to illustrate the problem. The problem is…
tintedFrantic
  • 177
  • 1
  • 9
1
2
3
9 10