I have numpy arrays of following form:
rand_pos = [[1,2,2],[2,3,4],[1,2,5],[3,2,1]...] #here, total subarrays = 900
gal_pos = [[2,3,4],[56,6,64],[34,45,65]...] #here, total subarrays ~ 10^6
Right now, my program picks out one sublist from rand_pos to do the following operations:
pos2=np.array(rand_pos[0])
dist_xyz = np.subtract(pos2,gal_pos)
dist_square_xyz = np.square(dist_xyz)
axis = 1
dist_square_sum = dist_square_xyz.sum(axis)
dist_sqrt = np.sqrt(dist_square_sum)
list_gal_dist_in_sphere = dist_sqrt[abs(dist_sqrt) <=radius]
gal_number = len(list_gal_dist_in_sphere)
How can I send all the sublists from rand_pos and do this operation on all of them? I know I can loop over the rand_pos, sending one sublist at a time but is there any other way to do it?
len(dist_sqrt[abs(dist_sqrt) <=radius]might be better speltnp.count_nonzero(abs(dist_sqrt) <= radius)