Question: Write a short program that uses numpy to create a one-dimensional array with 1000 random numbers between 1 and 100 and print out shape and
Write a short program that uses numpy to create a one-dimensional array with 1000 random numbers between 1 and 100 and print out shape and datatype of the array. Use numpys functions to print the min, max, sum, mean and standard deviation of the values in your array.
Examples for the functions you need to use are (after importing numpy as np) np.random.randint(100, size = 10) #creates an array of 10 integer elements of up to 100 in value)
myArray.ndim #shows dimensions of the array myArray.shape #shows the shape of the array
myArray.datatype #shows the type of the array values
Also needed are : np.min(), np.max(), np.sum(), np.mean) and np.std() where you specify your array in the parenthesis
Part 4: Sorting Numpy offers various methods for sorting your array. Make the size of the array a variable and explore the runtimes of the following three sorting methods by timing how long it takes to sort one-dimensional arrays with integer values between 0 and 100, varying the size of the array. Quicksort: default sorting algorithm used with np.sort() Mergesort: np.sort(data, kind='mergesort') Heapsort: np.sort(data, kind='heapsort')
Hand in your documented source code and your observations about the runtimes for the sorting algorithm as the size of the array increases.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
