How can I achieve:
>>> foo = np.array([1,2,3])
array([1,2,3])
>>> foo.append(4)
array([1,2,3,4])
Instead of numpy's:
np.append(foo, 4)
I've tried stuff along the lines of:
import numpy as np
class myarrayclass(np.array):
def append(self, value):
self.object = np.append(self.object, value)
Also, is it possible to overwrite the numpy class instead of creating my own? I don't need this to work, just wondering if it is possible, thanks in advance!
np.appendbefore you try this. It is not a listappendclone, and shouldn't be treated as one.resizemethod. That can add zeros in-place. It may be instructive to look at the code for thenp.resizefunction, which does not operate in place. Rather it usesconcatenateandreshape, making a new array.