Python: Splitting numPY 2 D Array

0 votes
Please let me know how to split a 2D numPy array with example code. Thanks
Jul 15 in Python by Tina
51 views

1 answer to this question.

0 votes

For splitting the 2d array,you can use two specific functions which helps in splitting the NumPy arrays row wise and column wise which are split and hsplit respectively .

1. split function is used for Row wise splitting.

2. hsplit function is used for Column wise splitting .

The simplest way of splitting NumPy arrays can be done on their dimension. A 3 * 4 array can easily be broken into 3 sets of lists for Rows and 4 set of lists using Columns. Here is how we can do the same :

import numpy as np

arr = np.array([[1,2,3,4],

                [5,6,7,8],

                [9,10,11,12]])


arr.shape

# Displays (3,4)


#Split Row Wise

np.split(arr,3)

#Splitted as --> [1,2,3,4] | [5,6,7,8] | [9,10,11,12]


#Split Column Wise

np.hsplit(arr,4)

#Splitted as --> [1,5,9] | [2,6,10] | [3,7,11] | [4,8,12]
answered Jul 15 by Siri

Related Questions In Python

0 votes
1 answer
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 67,290 points

edited Aug 8, 2018 by Omkar 479 views
0 votes
1 answer

How to save Numpy array as image in python?

If you have matplotlib, you can do: import ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,500 points
1,316 views
+4 votes
7 answers

Splitting a List into chunks in Python

Here's a generator that yields the chunks ...READ MORE

answered Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
3,885 views
+1 vote
3 answers

What are the ways of detecting outliners in Python

code from http://eurekastatistics.com/using-the-median-absolute-deviation-to-find-outliers  This uses the L1 distance ...READ MORE

answered Aug 24, 2018 in Python by eatcodesleeprepeat
• 4,670 points

reshown Aug 24, 2018 by Priyaj 58 views
0 votes
1 answer
0 votes
1 answer
+4 votes
7 answers