2

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...
lee.edward01
  • 453
  • 1
  • 6
  • 16
  • 2
    Possible duplicate of [Downsampling a 2d numpy array in python](https://stackoverflow.com/questions/34231244/downsampling-a-2d-numpy-array-in-python) – Bart May 17 '18 at 17:11
  • 1
    Sorry, misread your question, the duplicate I suggested isn't really the answer here. – Bart May 17 '18 at 17:26

1 Answers1

4

You are probably looking for np.split()

  • np.split() splits it into the number assigned, I was hoping to split it every nth number, so if n = 3, it would split the array every 3rd row – lee.edward01 May 17 '18 at 17:21
  • @lee.edward01 You could pass an array with indexes to np.split() though. Maybe something like range(0,len(arr),3) – Anton vBR May 17 '18 at 17:21
  • 1
    Just divide the length of your input array by 3 and you get the number of slices: np.split(arr, len(arr)/3) – NullAchtFuffZehn May 17 '18 at 17:24