...

Web Technologies - NumPy

Back to Course

Lesson Description


Lession - #303 NumPy Array Split


Splitting NumPy Arrays

Splitting is converse activity of Joining.
Joining combines various arrays into one and Splitting breaks one array into numerous.
We use array_split(>
for dividing arrays, we pass it the array we need to split and the quantity of splits.

Example
Split the array in 3 parts:
import numpy as np

arr = np.array([1, 2, 3, 4, 5, 6]>
newarr = np.array_split(arr, 3>
print(newarr>


Split Into Arrays

The return worth of the array_split(>
method is a array containing every one of the split as an array .
On the off chance that you split a array into 3 arrays, you can get to them from the outcome very much like any array component:

Example
Access the splitted arrays:
import numpy as np

arr = np.array([1, 2, 3, 4, 5, 6]>
newarr = np.array_split(arr, 3>
print(newarr[0]>
print(newarr[1]>
print(newarr[2]>


Splitting 2-D Arrays

Utilize a similar sentence syntax while dividing 2-D arrays.
Utilize the array_split(>
method, pass in the array you need to part and the quantity of splits you need to do.

Example
Split the 2-D array into three 2-D arrays.
import numpy as np

arr = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]]>
newarr = np.array_split(arr, 3>
print(newarr>


Example
Split the 2-D array into three 2-D arrays.
import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]]>
newarr = np.array_split(arr, 3>
print(newarr>










This python numpy tutorial blog includes all the basics of Python, its various operations, special functions
How to take array input in python? ; a=[] ; n=int(input("Number of elements in array:">
>
; for i in range(0,n>
: ; l=int(input(>
>
; a. · append(l>
.
We can create matrix Python using a nested list.
Introducing NumPy and Pandas ... NumPy is a library for Python that adds support for large, multi-dimensional arrays and matrices, along with a large collection .
Python Array Example – Declare, Append, Index, Remove, Count · 'b' -> Represents signed integer of size 1 byte · 'B' -> Represents unsigned .