add data from new numpy.ndarray in the end of numpy.ndarray in python

To add data from a new numpy.ndarray at the end of another numpy.ndarray in Python, you can use the numpy.append() function. Here is an example:

main.py
import numpy as np

# Create the first ndarray
arr1 = np.array([1, 2, 3])

# Create the second ndarray
arr2 = np.array([4, 5, 6])

# Append the second array to the end of the first array
result = np.append(arr1, arr2)

print(result)
233 chars
13 lines

Output:

main.py
[1 2 3 4 5 6]
14 chars
2 lines

In the example above, we first create two numpy ndarrays arr1 and arr2 with different values. Then, we use the numpy.append() function to append arr2 at the end of arr1. The result is stored in the result variable and printed.

Note that numpy.append() returns a new array with the concatenated values, so we assigned it to a new variable (result) to store the final result.

related categories

gistlibby LogSnag