Ad

Making A 0 To Nxn Matrix And Reshape It To Pairs

- 1 answer

Maybe I am wrong and I don't know how to search for it.

I need to get a list of pairs

(0,0) (0,1) (0,2) ... (0,999) ... (999,999)

To put these values into a neural network and get the result - just a vector of length (999*999)

Then I can reshape it to (999,999) and have a map of outputs.

So, naive approach is to use

for i in range(0, 999):
    for j in range(0, 999):
        list.add(predict(i,j))

But it is impossible to use batches

Another naive approach is

numbers=[]
for i in range(0, 999):
    for j in range(0, 999):
        numbers.append([i,j])

and this works in batches.

Is there any more elegant solution?

Ad

Answer

Try this:

target_list = np.array([(i,j) for i in range(1000) for j in range(1000)])

This print(target_list) will give desired list in numpy array format:

[[  0   0]
 [  0   1]
 [  0   2]
 ...
 [999 997]
 [999 998]
 [999 999]]
Ad
source: stackoverflow.com
Ad