python - Numpy array creation -
first off apologize arbitraryness of question rewriting of scripts use numpy arrays instead of nested python lists (for performance , memory) i'm still struggling declaration.
i trying create structure using numpy arrays, starting off 1000 (arbitrary value) elements in array each element should contain float (as [x][0]) , nested array containing coordinates (so 10.0000 x 2 floats per top level element) (as [x][1], each element in nested array accessible [x][1][y][z] y element in nested array , z specified of 2 coordinates). following question nested structured numpy array creates nigh identical structure (as reference question , desired structure).
schematic raw data example:
time 0 m/z 10 int 10 m/z 20 int 20 m/z 30 int 1000 ... time 1 <repeat>
i have read haveto use dtype part define nested array not quite sure on declaration part of dimensions empty array, give me hand? here came far.
data=np.zeroes((1000,2 /* add nested array */), dtype=[('time', 'f'), [('m/z','f'), ('intensity','f')]])
ps: matrix might better option this?
>>> = np.zeros(1000, dtype='float32, (10000,2)float32') >>> a[200][0] 0.0 >>> a[200][1][2000] array([ 0., 0.], dtype=float32)
note creates 1000 arrays of dimension (10000,2). that's fine if ever operations @ 1 of arrays. using separate (1000,10000,2) array instead take better advantage of vectorized operations in numpy. example increment second coordinates in 1 operation this:
>>> b = np.zeros((1000,10000,2)) >>> b[:,:,1] += 1
trying same a[:][1][:,1]
error.
Comments
Post a Comment