Append a NumPy array to an empty array using the append

Example 1

Here we are creating an empty array and then appending it to the array.

Python3




import numpy as np
  
l = np.array([])
l = np.append(l, np.array(['G', 'F', 'G']))
l = np.append(l, np.array(['G', 'F', 'G']))
print(l)


Output:

['G' 'F' 'G' 'G' 'F' 'G']

Example 2

Here we are creating an empty array and then appending an empty row in it to see if there is any difference.

Python3




import numpy as np
  
l = np.array([])
  
l = np.append(l, np.array([]))
l = np.append(l, np.array(['G', 'F', 'G']))
l = np.append(l, np.array(['G', 'F', 'G']))
  
print(l)


Output:

We can see that there is no difference in output.

['G' 'F' 'G' 'G' 'F' 'G']

How to append a NumPy array to an empty array in Python

In this article, we will cover how to append a NumPy array to an empty array in Python.  Here, we will discuss 2 different methods to append into an empty NumPy array. Both of these methods differ slightly, as shown below:

Similar Reads

Append a NumPy array to an empty array using the append

Example 1...

Append a NumPy array to an empty array using hstack and vstack

...

Contact Us