Is there a general way to vectorize these kind of operations in NumPy?
In [2]: N = 8
In [3]: ll = np.arange(8)
In [4]: arr = np.zeros(ll.shape + (2, 2))
In [5]: ll.shape
Out[5]: (8,)
In [6]: arr.shape
Out[6]: (8, 2, 2)
In [7]: for ii in range(N):
...: arr[ii, :, :] = np.array(...) # 2 x 2 array function of ll[ii]
if that function is a linear operation on ll then this would be trivial, but is there a way to do it in the general case? Just to put an example:
In [8]: for ii in range(N):
...: arr[ii, :, :] = np.array([
...: [np.cos(ll[ii]) - 1, 0],
...: [np.sin(ll[ii]), np.cos(ll[ii]) ** 2]
...: ])