Split an array of 10 elements into 3 arrays using NumPy.

In this python numpy program, we will split an array of 10 elements into 3 arrays using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Split an array of 10 elements into 3 arrays, each of which has 2, 3, and 5 elements using np.split().
  4. Print the output.
				
					import numpy as np
x = np.arange(1, 11)
print("Original array:",x)
print("After splitting:")
print(np.split(x, [2, 5]))
				
			

Output :

				
					Original array: [ 1  2  3  4  5  6  7  8  9 10]
After splitting:
[array([1, 2]), array([3, 4, 5]), array([ 6,  7,  8,  9, 10])]
				
			

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

get the number of nonzero elements in an array.

Leave a Comment