randomly replace rows by other rows in python -


first, reads data file , transpose. fine here.

next, generates 2 random samples r1 , r2. fine here.

last, generates matrix same shape data, , use loop loop r1 , r2 simultaneously, replace row j data[j,:] + data[i,:]. (using print(sum(data[j,:] + data[i,:]), sum(r_data[j,:])) check if works). fine till now.

but finally, when check r_data, elements 0. don't why, did make mistakes? appreciate help!!!

ps, tried replacing data data = np.ones((n,k)), , works. have no idea how bug happens. happens when read data file.

import numpy np  data = np.loadtxt("nonames.txt") data = np.transpose(data) n = len(data[:,0]) k = len(data[0,:])  # randomly merging samples c =  np.arange(n) r1 = np.random.choice(c, 500, replace=false) r2 = np.random.choice(c, 500, replace=false) r_data = np.zeros((n,k)) i,j in zip(r1,r2):     r_data[j,:] = data[j,:] + data[i,:]     print(sum(data[j,:] + data[i,:]), sum(r_data[j,:])) 


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -