It is quite complicated to reproduce this in a simplified way but I will give it a try. I hope it will be clear.
First of all I have an array of the form:
Thank you!
First of all I have an array of the form:
first_array=np.array([0, 0, 0, 0, 0, 1, 2, 2, 2, 3, 3, 4], dtype=int64)Then I have a function_a that takes this array and calculates a value for each entry which is summed up in a 1-dimensional array with the length of 5. It is hard to find an easy example for this calculation without posting a ton of code, so this is replaced here by a simple random_function, that returns an array of dtype=64 (not modifiable unfortunately):
def function_a(first_array): total_results = [0 for i in range(5)] for row_index in range(first_array.shape[0]): total_results += random_function([row_index]) return total_results def random_function(entry_array): result_for_entry = np.random.choice([0, 1], size=5, p=[.1, .9]) result_for_entry = result_for_entry.astype(np.int64) return result_for_entry function_a(first_array)
Output:array([ 9, 11, 10, 12, 11], dtype=int64)
But I have to to this for a larger data set of this example form (here only 5 arrays are assumed, in fact there are 15.000):testdata=np.array([array([0, 0, 0, 0, 0, 1, 2, 3, 3, 3, 4, 4], dtype=int64), array([0, 1, 2, 2, 2, 3, 3, 4, 4], dtype=int64), array([0, 0, 1, 3, 4], dtype=int64), array([0, 0], dtype=int64), array([0, 1, 2, 2, 4, 4], dtype=int64)], dtype=object)For this purpose I wrote function_b which results in the mentioned result structure of a list of arrays:
def function_b(testdata): results = [[0 for i in range(5)] for k in range(5)] for i in range(5): results[i] = function_a(testdata[i]) return results function_b(testdata)
Output:[array([12, 10, 11, 12, 11], dtype=int64),
array([8, 7, 9, 8, 7], dtype=int64),
array([5, 5, 5, 5, 5], dtype=int64),
array([2, 2, 2, 2, 2], dtype=int64),
array([6, 6, 6, 6, 5], dtype=int64)]
I hope I explained the structure in an understandable way. Help is much appreciated how I can get the final results as an array of lists.Thank you!