Is there an alternative way to create a numpy array filled with a character, e.g.:
p = np.array( [' '] * 12 )
Is there a way to use np.full(...)
?
Use the numpy. ones() function to create a numpy array of a specified shape that is is filled with the value one (1).
fill() method is used to fill the numpy array with a scalar value. If we have to initialize a numpy array with an identical value then we use numpy. ndarray. fill().
The elements of a NumPy array, or simply an array, are usually numbers, but can also be boolians, strings, or other objects.
Starting from numpy 1.4, if one needs arrays of strings, it is recommended to use arrays of dtype object_ , string_ or unicode_ , and use the free functions in the numpy. char module for fast vectorized string operations.
Yes np.full
could be used with the correct datatype (string) being mentioned with it, like so -
np.full((12), [' '],dtype=str)
You can also use np.repeat
-
np.repeat([' '], 12)
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