I have a specific array with dtype = object
, the array elements represent couples of coordinates at different times and I want to reshape it into an easier format.
I managed to do this for "one time", but I can't get it to work for all time observations.
The length of each observation is different so perhaps I must use masked values to do that. Below is an example that I hope explains better what I want.
# My "input" is:
a = np.array([[], [(2, 0), (2, 2)], [(2, 2), (2, 0), (2, 1), (2, 2)]], dtype=object)
#And my "output" is:
#holding_array_VBPnegl
array([[2, 0],
[2, 2],
[2, 1]])
#It doesnt consider my for loop in a.shape[0], so the expected result is :
test = np.array([[[True, True],
[True, True],
[True, True]],
[[2, 0],
[2, 2],
[True, True]]
[[2, 0],
[2, 2],
[2, 1]]])
#with "True" the masked values
I have tried using code I found on StackOverflow:
import numpy as np
holding_list_VBPnegl=[]
for i in range(a.shape[0]):
for x in a[i]:
if x in holding_list_VBPnegl:
pass
else:
holding_list_VBPnegl.append(x)
print holding_list_VBPnegl
holding_array_VBPnegl = np.asarray(holding_list_VBPnegl)