Assignment 4 - Jupyter Notebook
Assignment 4 - Jupyter Notebook
1.Create a 3 X 5 integer array (any values) and print its attributes (length, size, dimensions).
[ 5, 6, 7, 8, 9],
In [2]: len(a)
Out[2]: 3
In [3]: a.ndim
Out[3]: 2
In [4]: a.size
Out[4]: 15
2.Using NumPy Create a 4 X 5 integer array from a range between 100 to 200 such that
thedifference between each element is 5.
Expected_Output:
[[100 105 110 115 120]
[125 130 135 140 145]
[150 155 160 165 170]
[175 180 185 190 195]]
3.Given the following Numpy array: my_array = np.array([[11 ,22, 33], [44, 55,
66], [77, 88, 99]]) ,
Write a Python syntax to return array of items in the second column from all
rows. Your codeshould return the following
output: [22 55 88]
[[11 22 33]
[44 55 66]
[77 88 99]]
In [7]: print(my_array[::,1])
[22 55 88]
4.Delete the third column from the given array my_array and insert the
following new_column in its place.
Original array:
[[54 23 89]
[80 12 24]
[37 49 71]]
Expected Output:
[[54 23 11]
[80 12 11]
[37 49 11]]
In [9]: my_arrays[::,2]=11
In [10]: print(my_arrays)
[[54 23 11]
[80 12 11]
[37 49 11]]
Original array:
Minimum Value of 0:
Maximum value of 1:
6.Write a function analyze(array) which prints out the minimum ,maximum , mean,
and median values of the provided array and returns a dictionary containing
these values underappropriate keys.
Function call:
analyze(np.array([1,5,2,4,3]))
Expected Output:
{"minimum":1,"maximum":5,"mean":3,"median":3}
Input 1:
my_array = np.linspace(-5,5,75)
trigonometric_plot(my_array, sin)
Expected output: Should plot a sin curve
localhost:8888/notebooks/Downloads/Numpy_Studentcopy/Numpy_Studentcopy/Assignment 4.ipynb# 3/6
4/30/22, 2:32 PM Assignment 4 - Jupyter Notebook
Input 2:
my_array = np.linspace(-5,5,75)
trigonometric_plot(my_array, cos)
Expected output: Should plot a cosine curve
8. Read the given file weight_height_data.csv. Plot the given data ( height vs
weight) as a scatterplot using the Matplotlib
library.
9. Compute the BMI for each pair of data-points from Q.8 above. Add the BMI
values as a newcolumn. BMI = (weight in kgs)
/(height in meters)^2 (Hint: Be careful with the units!)
10. Finally, compute the average BMI using the data from Q.9 above.
In [19]: Sum_BMI=dp["BMI"].sum()
Num_BMI=len(dp["BMI"].index)
Ave_BMI=Sum_BMI/Num_BMI
print("the average BMI is",Ave_BMI)
In [ ]: