1

I have a 1d numpy ndarray with shape (1,2).

nd = array[1,0]

I want to convert it into a ndarray with shape (n,2) such that it will look something like this;

nd_new = [
            [1,0]
            [1,0]
            [1,0]
            ...
            ...
            [1,0]
         ]

There are n rows of [1,0].

user3848207
  • 3,737
  • 17
  • 59
  • 104

2 Answers2

1

You can use np.tile as follows:

>>> np.tile(nd, (n, 1))
a_guest
  • 34,165
  • 12
  • 64
  • 118
0

I will answer my own question. Use the one hot encoding tools from keras.

from keras.utils import to_categorical
y_nd_ones = [1] * n
y_nd = to_categorical(y_nd_ones)
user3848207
  • 3,737
  • 17
  • 59
  • 104