I have two arrays a
and b
. If I run a.shape
I get (10,)
and if I run (b.shape)
I get (10,)
however each of those values are arbitrarily nested arrays which are not equal in shape to the others in itself or to the corresponding value in the other array. For example a[0].shape
returns (122,)
and b[0].shape
returns (3900,)
and b[5].shape
returns (5200,64)
so they aren't even consistent within the same array.
I know that they have the same total number of elements using the recursive solution found at Iterating through a multidimensional array in Python (no standard numpy functions seemed to be able to drill as deeply as necessary into the arrays):
def iterThrough(lists):
if not hasattr(lists[0], '__iter__'):
for val in lists:
yield val
else:
for l in lists:
for val in iterThrough(l):
yield val
si = 0
for value in iterThrough(a): #and b
si += 1
Both return 3066752
. I understand that this is quite messy, but I need it to be in that shape to compute a mathematical function later on and I'm guessing it's easier to to do this than to rewrite that equation to reflect a nicely formatted array.
How can I make array a
exactly identical in all its nested shapes to array b
?