How do I erase a whole array, leaving it with no items?
I want to do this so I can store new values in it (a new set of 100 floats) and find the minimum.
Right now my program is reading the minimum from sets before I think because it is appending itself with the previous set still in there. I use .append by the way.
Using the NumPy function np. delete() , you can delete any row and column from the NumPy array ndarray . Specify the axis (dimension) and position (row number, column number, etc.). It is also possible to select multiple rows and columns using a slice or a list.
If you are using numpy arrays then the_array[...] = 0 should do the trick.
Using list.list. clear() is the recommended solution in Python 3 to remove all items from the list.
Note that list
and array
are different classes. You can do:
del mylist[:]
This will actually modify your existing list. David's answer creates a new list and assigns it to the same variable. Which you want depends on the situation (e.g. does any other variable have a reference to the same list?).
Try:
a = [1,2] b = a a = []
and
a = [1,2] b = a del a[:]
Print a
and b
each time to see the difference.
It's simple:
array = []
will set array
to be an empty list. (They're called lists in Python, by the way, not arrays)
If that doesn't work for you, edit your question to include a code sample that demonstrates your problem.
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