python - Array formatting with numpy? -


i'm trying create numpy array mathematical processing , can't seem format code correctly. have signals numpy array: 'a','b','c','d','e' want "headers" or 0th row of array. following rows want insert value same numpy array signals stored, where:

values = np.array(dat_arr[:,7])  signals = ['a','b','c','d','e'] 

i know formatting [[signals],[values]] incorrect want array outputs like:

[a, b, c, d, e,  3, 4, 7, 5, 8,  5, 2, 1, 6, 9] 

etc.

i new programming numpy , python. ideas?

you can using structured types. text file content:

a, b, c, d, e 3, 4, 7, 5, 8 5, 2, 1, 6, 9 

you can do:

a = np.genfromtxt('test.txt', names=true, delimiter=',') 

in order obtain kind of structured array, allows do:

print(a['a']) #[ 3.  5.] 

edit:

you can obtain structured array list of lists well, in case like:

values = [[3, 4, 7, 5, 8],           [5, 2, 1, 6, 9]] signals = ['a','b','c','d','e']  = np.rec.array(values, dtype=list(zip(signals, [float]*len(signals)))) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -