Generate an array of integers from 0 to 99 and split it into two smaller arrays. Each smaller array will contain half of the original.

Import numpy

originalArray = numpy.range(100)

split1 = originalArray[:len(originalArray)/2] #The use of a :X as an index into an array means that you want all values from the start to the Xth value

split2 = originalArray[len(originalArray)/2:] #The use of a X: as an index into an array means that you want all values from the Xth value to the end

SH

Related Python Mentoring answers

All answers ▸

Describe both For-loops and While-loops and explain how you can simulate the effect of a for loop with a while loop with an example.


How would you loop over every key and value in a python dictionary?


Create a python code to sum the number from 1 to 10.


What would output this code? print(hello world)