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, 2019 in Python by Tina
17,192 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]


This should work.

To know more, It's recommended to join our Python Training in Chennai today.

answered Jul 15, 2019 by Siri

edited Oct 7, 2021 by Sarfaraz

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 5, 2018 in Python by Omkar
• 69,220 points

edited Aug 8, 2018 by Omkar 8,180 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,560 points
8,970 views
0 votes
1 answer

Convert a NumPy array to a tuple in Python.

Hi@akhtar, You can use the tuple keyword in ...READ MORE

answered Jun 29, 2020 in Python by MD
• 95,460 points
2,492 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,710 points

reshown Aug 24, 2018 by Priyaj 1,378 views
0 votes
1 answer

How to create Pandas series from numpy array?

Hi. Refer to the below command: import pandas ...READ MORE

answered Apr 1, 2019 in Python by Pavan
3,517 views
0 votes
1 answer
0 votes
1 answer
+4 votes
7 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP