add data from new numpy.ndarray with shape (6, 28, 28) in the end of numpy.ndarray (10000, 28, 28) in python in python

To add data from a new numpy.ndarray with shape (6, 28, 28) at the end of an existing numpy.ndarray with shape (10000, 28, 28) in Python, you can use the numpy.concatenate() function.

Here's an example of how to do it:

main.py
import numpy as np

# Create the existing array with shape (10000, 28, 28)
existing_array = np.zeros((10000, 28, 28))

# Create the new array with shape (6, 28, 28)
new_array = np.ones((6, 28, 28))

# Concatenate the arrays along the first axis (axis=0)
result = np.concatenate((existing_array, new_array), axis=0)

# Check the shape of the resulting array
print(result.shape)  # Output: (10006, 28, 28)
404 chars
14 lines

In the example above, we first create the existing_array with shape (10000, 28, 28) and initialize it with zeros. Then, we create the new_array with shape (6, 28, 28) and initialize it with ones.

Finally, we use the np.concatenate() function to concatenate the arrays along the first axis (axis=0), which corresponds to adding the new_array at the end of the existing_array. The resulting array is stored in the variable result.

gistlibby LogSnag