Q:

Split the array into four equal-sized sub-arrays using python programming

belongs to collection: Python NumPy Exercises

0

Split the array into four equal-sized sub-arrays

Note: Create an 8X3 integer array from a range between 10 to 34 such that the difference between each element is 1 and then Split the array into four equal-sized sub-arrays.

Expected Output:

Creating 8X3 array using numpy.arange
[[10 11 12]
 [13 14 15]
 [16 17 18]
 [19 20 21]
 [22 23 24]
 [25 26 27]
 [28 29 30]
 [31 32 33]]

Dividing 8X3 array into 4 sub array

[array([[10, 11, 12],[13, 14, 15]]), 
array([[16, 17, 18],[19, 20, 21]]), 
array([[22, 23, 24],[25, 26, 27]]), 
array([[28, 29, 30],[31, 32, 33]])]

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy

print("Creating 8X3 array using numpy.arange")
sampleArray = numpy.arange(10, 34, 1)
sampleArray = sampleArray.reshape(8,3)
print (sampleArray)

print("\nDividing 8X3 array into 4 sub array\n")
subArrays = numpy.split(sampleArray, 4) 
print(subArrays)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Sort following NumPy array using python programmin... >>
<< Create a result array by adding the following two ...