Suppose i already have a very large 2d matrix(like [10000,10000]) and i want to create a new matrix A(like [10000,10000,2]) such that A[i,j,:]=[i,j] The intuitive way is as follows:
import numpy as np
c = np.zeros([10000,10000,2])
d1,d2 = c.shape[:2]
for i in range(d1):
for j in range(d2):
c[i,j,:] = (i,j)
# it's time-consuming
However, it's time comsuming
I decide to use broadcast :
d = np.zeros([10000,10000,2])
d[:,:,0] = np.arange(10000).reshape(10000,1) + np.zeros(10000)
d[:,:,1] = np.arange(10000).reshape(1,10000) + np.zeros(10000).T
It works.
But Is there any other way to do this? I am newbee to deal with these kinds of large matrices, so I decided to look for some information about it.At first I thought it belongs to the fields of big data.Apparently,i am wrong. Where can I find some information? Thank you so much for your reply and advice.