Append a NumPy array to an empty array using hstack and vstack
Here we are using the built-in functions of the NumPy library np.hstack and np.vstack. Both are very much similar to each other as they combine NumPy arrays together. The major difference is that np.hstack combines NumPy arrays horizontally and np. vstack combines arrays vertically.
Python3
import numpy as np arr = np.array([]) arr = np.hstack((arr, np.array([ 'G' , 'F' , 'G' ]))) print (arr) arr = np.vstack((arr, np.array([ 'G' , 'F' , 'G' ]))) print (arr) |
Output:
['G' 'F' 'G'] [['G' 'F' 'G'] ['G' 'F' 'G']]
Contact Us