...

Web Technologies - NumPy

Back to Course

Lesson Description


Lession - #302 NumPy Array Join


Joining NumPy Arrays

Joining implies placing items in at least two arrays in a solitary array.
In SQL we join tables in view of a key, while in NumPy we join arrays by axes.
We pass a grouping of arrays that we need to join to the concatenate(>
function, alongside the axis. On the off chance that axis isn't expressly passed, it is taken as 0.

Example
Join 2 arrays
import numpy as np

arr1 = np.array([1, 2, 3]>
arr2 = np.array([4, 5, 6]>
arr = np.concatenate((arr1, arr2>
>
print(arr>


Joining Arrays Using Stack Functions

Stacking is same as concatenation, the main contrast is that stacking is done along another axis.
We can concatenate two 1-D arrays along the second axis which would bring about putting them one over the other, ie. stacking.
We pass a grouping of arrays that we need to join to the stack(>
technique alongside the axis. In the event that axis isn't unequivocally passed it is taken as 0.

Example
import numpy as np

arr1 = np.array([1, 2, 3]>
arr2 = np.array([4, 5, 6]>
arr = np.stack((arr1, arr2>
, axis=1>
print(arr>


Stacking Along Rows

NumPy provides a helper function: hstack(>
to stack along rows.

Example
import numpy as np

arr1 = np.array([1, 2, 3]>
arr2 = np.array([4, 5, 6]>
arr = np.hstack((arr1, arr2>
>
print(arr>


Stacking Along Columns

NumPy provides a helper function: vstack(>
to stack along columns.

Example
import numpy as np

arr1 = np.array([1, 2, 3]>
arr2 = np.array([4, 5, 6]>
arr = np.vstack((arr1, arr2>
>
print(arr>


Stacking Along Height (depth>

NumPy provides a helper function: dstack(>
to stack along height, which is the same as depth.

Example
import numpy as np

arr1 = np.array([1, 2, 3]>
arr2 = np.array([4, 5, 6]>
arr = np.dstack((arr1, arr2>
>
print(arr>







This simple bot code, along with the code explanation, is taken from the discord python documentation
The pydocs module automatically generates documentation from Python modules.
There are numerous methods for matrix addition python. This can be done using the for loop, using nested list comprehension, and also by using the zip(>
.
An ndarray is a (usually fixed-size>
multidimensional container of items of the same type and size. The number of dimensions and items in an array is defined by its shape , which is a tuple of N non-negative integers that specify the sizes of each dimension.