Reputation: 353
I want to modify my array by using like np.tile
other than using for loop
.
a = np.array(range(1,50)).reshape(-1,1)
a_new = np.tile(a, (100,1))
print(a_new)
will print out
[[1]
[2]
[3]
...
[48]
[49]
[50]
]
There will be 100 of [1][2]...[49][50]
, right?
However, I want to make a_new
like this below.
[[1]
[1]
[1]
...
[2]
[2]
[2]
...
[49]
[49]
[49]
...
[50]
[50]
[50]]
I want to create an array a_new
as 100 of [1], 100 of [2], ... 100 of [50]
.
How can I do this?
Upvotes: 1
Views: 65
Reputation: 153460
Try this:
np.repeat(a, 100).reshape(-1, 1)
output:
array([[ 1],
[ 1],
[ 1],
...,
[49],
[49],
[49]])
Upvotes: 1