Skip to content Skip to sidebar Skip to footer

Repeat Ndarray N Times

I have a numpy.ndarray with True/False: import numpy as np a = np.array([True, True, False]) I want: out = np.array([True, True, False, True, True, False, True, True, False])

Solution 1:

Use np.tile

>>>a = np.array([True, True, False])>>>np.tile(a, 3)...array([ True,  True, False,  True,  True, False,  True,  True, False])

Solution 2:

Try:

import numpy as np
a = np.array([True, True, False])
print(np.concatenate([a]*3))

[ TrueTrueFalseTrueTrueFalseTrueTrueFalse]

Post a Comment for "Repeat Ndarray N Times"