-3

I'm trying to create a 2d list with shape of [n,784] (the same shape as the MNIST image batches) using multiple [1,784] lists.

mylist.append(element) doesn't give me what I'm looking for, where mylist is the 2d [n,784] list and element is the [1,784] lists. It would return a list with shape [n,1,784].

I've also tried mylist[index].append(element), and I got a [784] 1d list instead.

Any idea how to solve my problem?

Thanks a lot

Xiaofan Mu
  • 17
  • 2
  • 6

2 Answers2

0
import numpy as np
myarray = np.array(mylist)
newarray = np.concatenate((myarray, element))

And if you want to turn it back into a list:

newlist = newarray.tolist()
Poke
  • 61
  • 7
0

a = [[1,1],[2,2]] b = np.concatenate([a, a], axis=1).tolist()

The output will be:

[[1, 1, 1, 1], [2, 2, 2, 2]]

ryan Li
  • 11
  • 1