An alternative (faster) way to do this would be with np.empty() and np.fill():
import numpy as np
shape = 10
value = 3
myarray = np.empty(shape, dtype=np.int)
myarray.fill(value)
Time comparison
The above approach on my machine executes for:
951 ns ± 14 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
vs using np.full(shape=shape, fill_value=value, dtype=np.int) executes for:
1.66 µs ± 24.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
vs using np.repeat(value, shape) executes for:
2.77 µs ± 41.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
vs using np.ones(shape) * value executes for:
2.71 µs ± 56.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
I find it to be consistently a little bit quicker.
numpy.reapeat(3, 10)...np.full(10, 3).repeat()(with only one 'a') ;)np.full(10, 3, dtype=np.int)otherwise it may be float result...np.ones(10) * 3.