I would like to sum through an array made of other sub-arrays.
import numpy as np
a1 = np.array([1,2,3])
a2 = np.array([3,4,5])
a3 = np.array([6,7,8])
a = np.concatenate(([a1],[a2],[a3]))
print(len(a))
for i in range(1,len(a)): (1)
for j in i : (2)
for k in j : (3)
goal = np.sum(np.cos(k))
print(goal)
goal to achieve :
goal = cos(1)+cos(2)+cos(3)
goal = cos(3)+cos(4)+cos(5)
goal = cos(6)+cos(7)+cos(8)
I thought of looping first on the array containing every other sub-array (1) , then for each sub-array (2) and finally inside each sub array (3) .
I'll get a traceback :
File "*****************", line 18, in <module>
for j in i :
TypeError: 'int' object is not iterable
In my real problem, I might have more than 3 sub-arrays. I think it can be done but I'm still discovering Python.