def arr_func(arr,selected_pixels_list):
rows = 2
m = 0
n = 0
i =0
#Calculate the number of pixels selected
length_of_the_list = len(selected_pixels_list)
length_of_the_list = int(length_of_the_list/4)*4
cols = int(length_of_the_list/2)
result_arr = np.zeros((rows,cols))
while(i<length_of_the_list):
result_arr[m,n] = arr[selected_pixels_list[i]]
result_arr[m,n+1] = arr[selected_pixels_list[i+1]]
result_arr[m+1,n] = arr[selected_pixels_list[i+2]]
result_arr[m+1,n+1] = arr[selected_pixels_list[i+3]]
i = i+4
m = 0
n = n+2
return result_arr
import numpy as np
selected_pixel_data = np.load("coordinates.npy")
arr_data = np.load("arr.npy")
response = arr_func(arr_data, selected_pixel_data)
print(response)
I try using "for loop" but it is not refractory.
for i in range(0,len(selected_pixels_list),4):
n=i//2
result_arr[m,n] = arr[selected_pixels_list[i]]
result_arr[m,n+1] = arr[selected_pixels_list[i+1]]
result_arr[m+1,n] = arr[selected_pixels_list[i+2]]
result_arr[m+1,n+1] = arr[selected_pixels_list[i+3]]
For selected_pixel_data:
shape = (597616, 2)
dtype = int32
For arr_data:
shape = (1064, 590)
dtype = float64
Here arr_data is an array of data and selected_pixel_data is coordinates. The function arr_func is used to create a new array with selected coordinates. Is there any way to use the code more efficiently?
.npy
files? \$\endgroup\$m = 0
over and again looks uncalled for. \$\endgroup\$refractory
as in heat/fire-proof, robust/resilient?) \$\endgroup\$