top of page

COMP132

For solutions, purchase a LIVE CHAT plan or contact us

1: Load data and get basic statistics (16 pts)
(a) Read sunspots.txt into a NumPy array, name it as sunspots.
(b) Show the data type of sunspots.
(c) Show the total number of elements.
(d) Show the maximum value.
(e) Show the minimum value and all the indexes where the elements are the minimum.
(f) Show the mean value and calculate the percentage of elements that are bigger than
the mean value.
(g) Find all the elements that are lower than the median value, sort them and save them
into a new file named ”sunspots low counts.txt”.
2: Index and subset (36 pts)
(a) Show the elements at index 36, 500, and 1000.
(b) Do the above step (2a) using one single line of statement.
(c) Show the 3rd last element.
(d) Show the last 10 elements using a single command.
(e) Show the elements between index 1100 and 1105 (inclusive) using a single command.
(f) Define a function with month (as numbers 1-12) and year as the parameters, make it
return the index of the sunspot counts in the given month and year. Then test your
function to find out:
• The index of sunspots observed in January (as 1) 1749.
• The index of sunspots observed in February(as 2) 1749.
• The index of sunspots observed in January (as 1) 1750.
• The index of sunspots observed in December(as 12) 1983.
Please note that this function is very important for the later questions, so you may
run more tests and make sure it is working properly.
(g) Define a function with month (as numbers 1-12) and year as the parameters, make it
return the count of sunspots in the given month and year. You should call the function
defined in (f) to get the index. Then test your function to find out:
• The number of sunspots observed in January (as 1) 1749.
• The number of sunspots observed in December(as 12) 1983.
• The number of sunspots observed in May (as 5) 1750. (answer: 90.0)
• The number of sunspots observed in April (as 4) 1876. (answer: 2.3)
If the results are not correct, it is likely your previous function in (f) is wrong.
(h) Define a function with year as the parameter, make it return an array of count of
sunspots in the given year. Then call your function to find out the sunspot counts in
the year 1795 and 1915.
Please note that this function is very important for the later questions, so test it using
boundary cases (e.g. 1749, 1983) to make sure it is working properly.
(i) Print all the elements in April between 1800 and 1850.
3: Detailed analyse (28 pts)
(a) Find the sum of sunspots counts in the year 1845.
(b) Find the maximum and minimum sunspots counts in 1769 and 1872, respectively.
(c) Write a function get average(year) that asks the user for a year, and returns the
monthly average of sunspots counts in that year. For example, with the parameter
of 1883, your function should return the average of sunspots counts for all months in
1883.
(d) For each corresponding month in 1800 and 1900, find out the smallest and biggest
difference of sunspots counts.
HINT: You may need abs(number) to get the difference for the cases when the year
1900 has lower counts.
(e) Find all the sunspot counts that are bigger than 200, print each element and index.
(f) Define a function get year and month(count) that asks the user for a sunspot count,
prints the month(s) and year(s) with the given count of sunspots. Then call your
function to find out the corresponding months and years that have the counts bigger
than 200.
HINT: Some months and years may have the same number of observed sunspots. For
a particular count, your function should print all the months and years that have this
count of sunspots. Please note the month should be printed in String format e.g Jan,
Feb, ...Dec.
(g) For each year between 1900-1910, find out the month having the highest number of
sunspots. Print the year, the month and the count. Please print the month in String
format (Jan, Feb,..., Dec).
4: Data Visualisation (20 pts)
(a) Make a line plot to show all the sunspot counts using blue dashed-line. Give a relevant
title for the plot and add labels on the x and y axes.
(b) Extract the counts of sunspots between the year 1800–1810 (inclusive) and 1900–1910
(inclusive), save them in two Numpy arrays called sunspots 1800 1810 and sunspots 1900 1910,
respectively. Plot the two arrays in the same plot, using different colours and line styles
to show the two arrays. Add labels and a title for your plot.
(c) Plot the two arrays in the same figure but with two subplots. Using different colours
and line styles to show the two subplots. Add labels, legend and titles for each sub-
figure.
(d) Extract the count of sunspots of the 19th century (1801–1900), save it in a Numpy
array called sunspots 19s. Create another Numpy array sunspots 19s shifted that shifts
the sunspots 19s data for 12 months lag. Plot the shifted data and original data in the
same plot. Using different colours and line styles to show the two arrays. Add labels
and a title for your plot.
HINT: Shifted lag data is quite popular in time series data analysis. Shifted data can
be created by shifting the elements of an array n places towards the right and replacing
the shifted elements with 0. For example, the shifted 3 lags of the array [1,2,3,4,5] is
[0,0,0,1,2].
HINT: When creating the shifted data, make sure that you do NOT change the
original array sunspots 19s.
(e) Save the figures created in 4(b) and 4(c) as image files (JPEG or PNG formats) in the
same directory.

For solutions, purchase a LIVE CHAT plan or contact us

Limited time offer:

Follow us on Instagram and tag 10 friends for a $50 voucher! No minimum purchase required.

bottom of page