Numpy savetxt loop -


using numpy, going split array of dimension (557124,2), dtype = "s10", in 6 subarrays using:

sub_arr = np.split(arr, 6) 

now use for loop on savetxt , save 6 subarrays 6 .txt files.

i tried:

for in sub_array:     np.savetxt(("subarray", i, ".txt"), sub_array[i], fmt='%s') 

there 2 problems:

  1. it's incorrect in sub_array. should use range(5) want make adaptable number of sub arrays.

  2. i thought use sort of "paste" in r when did ("subarray", i, ".txt"). there alike in numpy?

any idea?

from i've understood

sub_arr = np.split(arr, 6) 

returns list of 6 numpy arrays. can use enumerate each array , index

fname_template = "subarray.{i}.txt" i, sarr in enumerate(sub_arr):     np.savetxt(fname_template.format(i=i), sarr, fmt='%s') 

to create file name i've used new string formatting. otherwise can concatenate strings + "subarray."+str(i)+".txt", have make sure elements concatenate strings.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -