Please let me know how to split a 2D numPy array with example code. Thanks
Jul 15, 2019 in Python 16,591 views

## 1 answer to this question.

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

## How to slice an array using python numpy? Is there any numpy tutorial which has covered all its operations?

Slicing is basically extracting particular set of ...READ MORE

## 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

## How to save Numpy array as image in python?

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

## Convert a NumPy array to a tuple in Python.

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

+1 vote

## 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

## How do I obtain the index list in a NumPy Array of all the NaN values present using Python?

Hi, it is pretty simple, to be ...READ MORE

## How to create Pandas series from numpy array?

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

## Pandas series with custom index

You can do it by specifying index. ...READ MORE