Create a 1D numpy array that contains int values (4, 3, 1, 33, 21, 67, 27, 89, 34, 67, 99, 89, 12, 43). Hint: You can put these values in a python list and start from there.
Write code that prints values (67, 27, 89, 34). You must use the colon : based slicing approach to complete this task.
Your code should print the following: [67 27 89 34] Write code to print the average (mean) and median values for this array. You code should print the following: 42.07142857142857 for the mean 33.5 for the median
Source Code:
Output:
Code in text format (See above image of code for indentation):
#import numpy library
import numpy as np
#list of values
values=[4,3,1,33,21,67,27,89,34,67,99,89,12,43]
#create 1D numpy array
a=np.array(values)
#print array
print("Array is: ",a)
#print values using slicing
print(a[5:9])
#print mean
print("Mean: ",np.mean(a))
#print median
print("Median: ",np.median(a))
Get Answers For Free
Most questions answered within 1 hours.