Python/Numpy Slicing an array every nth row

Question:

I’m new to Numpy and data analysis in general and I was wondering what I had to do to/if it is possible to take a large array and splice it into smaller array. For example if I had a large 2D array like:

[[ 24.47590959 148.14814815 185.11662347 377.92894936 345.78146611]
 [ 24.74543137 147.49262537 185.7959032  375.93984962 346.86090878]
 [ 23.9300286  144.6131598  182.99098769 376.08123355 356.31569571]
 [ 24.68922439 145.01160093 181.35654697 382.11692778 363.30608538]
 [ 24.16976845 142.98991921 183.0328544  355.68202027 355.74528637]
 [ 23.66695856 139.94821916 181.78512998 352.4539607  348.73583261]
 [ 23.66219845 137.08958805 181.34010336 345.84125886 347.94711204]
 [ 23.53356475 135.34546931 179.85611511 352.82702655 350.32404975]
 [ 23.46866933 136.16557734 180.261379   354.29583702 366.703337  ]
 [ 23.46564044 133.71665441 179.09913137 346.08063679 358.48718408]
 [ 23.65184484 135.34546931 178.30079344 354.79865177 352.0506953 ]
 [ 22.55961378 136.23050201 176.41351328 358.93754487 342.52440486]
 [ 22.34936528 135.92496942 177.65144786 362.84470247 344.64931932]
 [ 22.6072999  137.04262025 176.64723547 361.20642947 347.82608696]
 [ 22.2585779  133.32444504 174.77934108 357.97386791 329.97855139]
 [ 21.62162162 128.09017548 173.05529117 360.94567768 333.05578684]
 [ 21.40983782 128.44390213 178.57142857 370.64492216 328.19166393]
 [ 20.8040776  127.4941034  182.34865062 369.07178446 333.72267646]
 [ 20.83333333 127.9590531  186.06381989 386.32412594 325.99837001]
 [ 20.08475768 129.11555842 184.55292055 380.22813688 315.95576619]
 [ 19.86531318 128.86597938 186.75880101 377.71482531 309.78934325]
 [ 20.47564933 130.76168683 189.35807612 374.25149701 321.64683178]
 [ 20.25090876 127.68945924 189.5195679  391.38943249 332.55736615]]

and I wanted to split the array every nth row, how would that be possible?

for example every third row would be:

[[ 24.47590959 148.14814815 185.11662347 377.92894936 345.78146611]
 [ 24.74543137 147.49262537 185.7959032  375.93984962 346.86090878]
 [ 23.9300286  144.6131598  182.99098769 376.08123355 356.31569571]]

 [[ 24.68922439 145.01160093 181.35654697 382.11692778 363.30608538]
 [ 24.16976845 142.98991921 183.0328544  355.68202027 355.74528637]
 [ 23.66695856 139.94821916 181.78512998 352.4539607  348.73583261]] etc...
Asked By: lee.edward01

||

Answers:

You are probably looking for np.split()

Answered By: NullAchtFuffZehn
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.