December 2017
Intermediate to advanced
386 pages
10h 42m
English
Joining arrays
Another way to create new arrays is to join, or concatenate, other arrays. There are several functions that make that easy. One common task is to create a two-dimensional array from its columns, and NumPy provides the column_stack() function for this specific purpose, as shown in the following example:
x = np.array([1,2,3])y = np.array([4,5,6])z = np.array([7,8,9])w = np.column_stack([x,y,z])
This produces the array:
array([[1, 4, 7], [2, 5, 8], [3, 6, 9]])
The concatenate() function is used to stack arrays along an arbitrary axis. The following example shows the concatenation ...
Read now
Unlock full access