In: Computer Science
1) Load the data from lab6_precipitation.csv into a numpy array; 2) Make a numpy array with the years 1916-2016 and dtype=int; 3) Make a numpy array with the months 1-12 and dtype=int; 4) Print out the shape of the data array and the lengths of the years and month array. If the length of your year array does not equal the number of rows in your data array, or the length of your months array does not equal the number of columns in your data array, you have done something wrong!
Please just post the code for these functions.
# import necessary libraries
import pandas as pd
import numpy as np
# Question 1: Load the data into numpy array
data = pd.read_csv('lab6_precipitation.csv', header = None).to_numpy()
# Question 2 : Make a numpy array with the years 1916-2016 and dtype=int;
years = np.arange(start=1916, stop=2017)
#print(years);
# Question 3 : Make a numpy array with the months 1-12 and dtype=int;
months = np.arange(start=1, stop=13)
#print(months)
# Question 4: 4) Print out the shape of the data array and the lengths of the years and month array.
print('Data Array shape : '+str(data.shape))
print('Year Array Length : '+str(years.size))
print('Month Array Length : '+str(months.size))
#print(data)
if data.shape[0]!=years.size or data.shape[1]!=months.size:
print('You have done something wrong!')
If you still have any queries, please feel free to post in comment box. I would be glad to help you.
If you like my explanation, please give a thumbs up. It really motivates us to provide a good quality work.