• Stacking together different arrays

     Several arrays can be stacked together along different axes.
    

* Axis of python

FIg-0. Basic concept of axis/dimension/wise of python.

FIg-1. To define different border style for different dimension array.


Numpy.vstack(), Numpy.hstack(), and Numpy.dstack()

We use two array a=[[1], [2], [3]] and b=[[4], [5], [6]] to explain numpy.vstack, numpy.hstack, and numpy.dstack methods.

Fig-2. Two arrays a = [[1], [2], [3]] and b = [[4], [5], [6]] for stack demo.


1. numpy.vstack((array a, array b))

Stack arrays in sequence vertically \(row wise\).
如同在垂直面上堆疊
  • example:

Fig-3. To perform numpy.vstack on google colab.

Fig-4. To explain numpy.vstack by picture.


2. numpy.hstack((array a, array b))

`Stack arrays in sequence horizontally (column wise).`
 如同在水平面上堆疊
  • example:

Fig-4. To perform numpy.hstack on google colab.

Fig-5. To explain numpy.hstack by picture.


3. numpy.dstack((array a, array b))

`Stack arrays in sequence depth wise (along third axis).`
 如同往深度堆疊

example:

Fig-6. To perform numpy.dstack method on google colab.

Fig-7. To explain numpy.dstack method by picture.


4. numpy.column_stack((array g, array h))

Stack 1-D arrays as columns into a 2-D array.

example:
We use two arrays g=[1, 2, 3] and h=[4, 5, 6] to explain numpy.column_stack() method.

Fig-8. Two array g=[1, 2, 3] and h=[4, 5, 6] to perform numpy.column_stack.

Fig-9. To perform numpy.column_stack on google colab.

Fig-10. To explain numpy.column_stack method by picture.


5. numpy.stack((array a, array b), axis=N)

Join a sequence of arrays along a new axis.

To create two array e=[[1], [2], [3]] and f = [[4], [5], [6]] to perform numpy.stack.

Fig-11. To perform numpy.stack((e, f)) on google colab, the axis default value is 0.

Fig-12. To explain numpy.stack((e, f)) method by picture.

Fig-13. To perform numpy.stack((e, f), axis=1) on google colab.

Fig-14. To explain numpy.stack((e, f), axis=1) by picture.

Fig-15. To perform numpy.stack((e, f), axis=2) on google colab.

Fig-14. To explain numpy.stack((e, f), axis=2) by picture.


Splitting one array into several smaller ones

Those commands can split an array along its axis, either by specifying the number of equally shaped arrays to return, or by specifying the columns after which the division should occur.

We use array sa = [[[0, 1], [2, 3]], [[4, 5], [6, 7]]] to explain those methods.

Fig-11. The array sa for perform numpy.split.


1. numpy.vsplit(array sa, int N)

Split an array into multiple sub-arrays vertically (row-wise).
  • sa: The input array.
  • N: Split an array into N sub-arrays

Fig-12. To perform numpy.vsplit on google colab.

Fig-13. To explain numpy.vsplit by picture.


2. numpy.hsplit(array sa, int N)

  • sa: The input array.
  • N: Split an array into N sub-arrays

Split an array into multiple sub-arrays horizontally (column-wise).

Fig-14. To perform numpy.hsplit on google colab.

Fig-15. To explain numpy.hsplit by picture.


3. numpy.dsplit(array sa, N)

  • sa: The input array.

  • N: Split an array into N sub-arrays

Split array into multiple sub-arrays along the 3rd axis (depth).

Fig-16. To perform numpy.hsplit on google colab.

Fig-17. To explain numpy.dsplit by picture.


numpy.array_split(array b, indices_or_sections)

(The same as numpy.split(array b, indices_or_sections))

Split an array into multiple sub-arrays.

Fig-18 Create an 2-D array b.

Fig-19 To perform numpy.array_split on google colab.

Fig-20 To explain numpy.array_split(b, (2, 3, 4)) by picture.

Fig-21 To explain numpy.array_split(b, 3) by picture.


results matching ""

    No results matching ""