'how to create an array of (100,19) size with each row as a vector of 19 values [0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] in python?

I need to create an array of size (100,19) in python where each row is a fixed 19 valued vector of value [0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]?

Any solution suggested?



Solution 1:[1]

a = np.zeros((100,19))
a[:,11] = 1

Solution 2:[2]

a = [0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
b = np.array(a)
c = np.tile(a,(100,1))
c.shape

Output:

(100, 19)

Solution 3:[3]

You can do it with np.zeros

array0 = np.zeros((100,19))
array0[:,11] = 1

On the other hand, if you want to have all one element

array1 = np.ones((100,19))
array1[:,11] = 0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Salvatore Daniele Bianco
Solution 2 PrinsEdje80
Solution 3 Kevin Choon Liang Yew