To append a value to a NumPy array in Python, we can use the numpy.append()
method.
Here is an example of how to use this method:
main.py218 chars11 lines
This will output:
main.py5 chars2 lines
Note that numpy.append()
returns a new array with the appended values and the original array is not modified. Therefore, we need to assign the returned value to a variable to keep the appended value.
We can also append multiple values at once by passing a sequence of values to numpy.append()
, for example:
main.py236 chars11 lines
This will output:
main.py11 chars2 lines
gistlibby LogSnag