Requirement:
I would like to make a function in python which is given 2 arrays, 1 bigger than the second one.
I would like the bigger one to take the same size that the smaller one.
BUT not only removing the end or beginning of the array I would like to keep a similar standard deviation of the chosen index of the bigger array.
For example :
For an array of size 10 and an array of size 95 the array of size 95 should become size 10 with for example the selected index [8, 17, 27, 36, 46, 55, 65, 74, 84, 93]
in pseudo-code an example of expected result would be :
len_bigger_array=95 # example where len(bigger_array)=95
len_smaller_array=10 # example where len(smaller_array)=10
result_array=[8, 17, 27, 36, 46, 55, 65, 74, 84, 93] #index of bigger_array with similar distance between each other
len(result_array)=10 #like len_small_array
1st Try :
total = len_bigger_array #len_bigger_array is len(bigger_array)
wanted = len_smaller_array #len_smaller_array is len(smaller_array)
div = 0
mod = 0
result_array = []
divider = int(total/wanted)
rest= total/wanted - divider
for x in range (0, total):
div=div+1
if (div >= divider):
if (mod >= 0.95):
div=div-1
mod=0
else:
result_array.append(x)
mod=mod+rest
div=0
print(result_array, len(result_array))
And the result of this try :
- for
len_bigger_array=95
andlen_smaller_array=10
it works :result_array=[8, 17, 27, 36, 46, 55, 65, 74, 84, 93]
andlen(result_array)=10
- for
len_bigger_array=1999
andlen_smaller_array=100
it works also :len(result_array)=100
and contain index of bigger_array with a similar distance between each - for
len_bigger_array=182
andlen_smaller_array=69
it doesn't work:result_array
contain index ofbigger_array
with a similar distance between each butlen(result_array)!=len_smaller_array
- for
len_bigger_array=95
andlen_smaller_array=33
it doesn't work:result_array
contain index ofbigger_array
with a similar distance between each butlen(result_array)!=len_smaller_array
2nd Try :
import math
total = len_bigger_array
wanted = len_smaller_array
result_array = []
divider = math.ceil(total/wanted)
for x in range (0, total):
if(x % divider == 0):
result_array.append(x)
missingSlice = wanted - len(result_array)
print(missingSlice)
if (missingSlice>0):
newWanted=int(total/missingSlice)
print(newWanted)
for x in range (0, total):
if (x % newWanted ==0 and x !=0):
if x not in l:
result_array.append(x)
else:
result_array.append(x-1)
print(result_array,len(result_array))
And the result of this try :
- for
len_bigger_array=95
andlen_smaller_array=10
it works :result_array=[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
andlen(result_array)=10
- for
len_bigger_array=1999
andlen_smaller_array=100
it works also :len(result_array)=100
and contain index of bigger_array with a similar distance between each - for
len_bigger_array=182
andlen_smaller_array=69
it works: also :len(result_array)=69
and contain index of bigger_array with a similar distance between each - for
len_bigger_array=95
andlen_smaller_array=33
it doesn't work:result_array
contain index ofbigger_array
with a similar distance between each butlen(result_array)=32
instead of 33
Context information :
smaller_array and bigger_array contain slice of CT image so they can vary.
the result array should contain index of bigger_array, those index should have a similar standard deviation between each other in order to compare similar area between smaller_array and bigger_array (that have the same beginning and ending point but different number of slice).