Suppose I have a 2D numpy array, say 5*3. Now I would like to map each element i in it to a new array [i, i*i], so the resulting array is 5*3*2.
What is the most efficient (and elegant) way to achieve this purpose?
A naive solution using for:
a = np.arange(15).reshape(5, 3)
r = []
for row in a:
_row = []
for i in row:
_row.append([i, i*i])
r.append(_row)
return np.array(r)