Now I have an numpy array X
with certain column names, format and length. How can I set all the values to 0
(or empty) in this array, without deleting the format/names etc.?
Use numpy.ndarray.fill
:
>>> import numpy as np
>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> a.fill(0)
>>> a
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
You can use slicing:
>>> a = np.array([[1,2],[3,4]])
>>> a[:] = 0
>>> a
array([[0, 0],
[0, 0]])
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