This is surely an easy question:
How does one create a numpy array of N values, all the same value?
For instance, numpy.arange(10)
creates 10 values of integers from 0 to 9.
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
I would like to create a numpy array of 10 values of the same integer,
array([3, 3, 3, 3, 3, 3, 3, 3, 3, 3])
Use numpy.full()
:
import numpy as np
np.full(
shape=10,
fill_value=3,
dtype=np.int
)
> array([3, 3, 3, 3, 3, 3, 3, 3, 3, 3])
Very easy 1)we use arange function :-
arr3=np.arange(0,10)
output=array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
2)we use ones function whose provide 1 and after we will do multiply 3 :-
arr4=np.ones(10)*3
output=array([3., 3., 3., 3., 3., 3., 3., 3., 3., 3.])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With