Answered step by step
Verified Expert Solution
Question
1 Approved Answer
d) From an array J by multiplying the array I (from Question 2d ) by factor of 10 . Convert the data type of elements
d) From an array J by multiplying the array I (from Question 2d ) by factor of 10 . Convert the data type of elements in array J from float to integer by using astype. Then form an array K that contains the elements which are odd numbers. Print array J and K. Then find the total number of elements in K. (10 marks) 4) You are given a task to study the revenue of the bubble tea shops owner of 4 franchises. Write the Python codes to solve the following problems. Type print() to display the answer. The information is given as following: i) Table 1: The number of cups of bubble tea sold by the franchise (daily) ii) Table 2: The price of a cup of bubble tea Tahlo ) a) Provide the array to show the revenue of each franchise. i. Write an array L to represent number of bubble tea drink (shown in Table 1). Print the array L. ii. Then write an array M to represent the price (Shown in Table 2). Print the array M. iii. Next, use matrix arithmetic operation between these two arrays to get the revenue. (Hints: Revenue =Q ty Price). Print the Output array N to show the revenue earned by each bubble tea shop. The expected shape of output array is 41. (12 marks) b) What is the total revenue of the owner? (Hints: total revenue=sum of the revenue from all franchises). The expected output of the revenue is shown below: The total revenue from all franchises is \$\{total_revenue . Note: Show total_revenue in 2 decimal places. (5 marks) c) Due to rising cost, the price of all bubble tea will be increased by $0.40. Find the new total revenue of the owner. (Hints: Apply arithmetic operators to get the new price based on the old price (array M in 4a (ii)). Then repeat the same step in 4a (iii) and 4b ). The output of the new revenue is shown: The new total revenue from all franchises is ${ new_total_revenue } Assumption: Same quantity of bubble tea sold by all franchises. (13 marks 1) Write the Python codes to solve the following problems. Type print() to display the answer. a) Create an (53) shape of array A using the following list. list1 =[0,6,36,9,1,16,5,34,30,4,10,31,27,26,11]. Print array A. (6 marks) b) Form array B, by using slicing method, get the output array B (from array A ) so that the array B is [/ 9 16] [27 11]] (6 marks) c) Form array C, by getting the interquartile range (IQR=Q3Q1) of the row of the array A (from 1a). Verify the shape of the array C. The expected shape of the array C is (5.). Print array C. (10 marks) 2) Write the Python codes to solve the following problems. Type print() to display the answer. a) Create a random integer matrix D from number 0 to 40 (with shape 66 ). Set the random seed to 20 and incorporate the following numpy command before generating the random number array D. Print array D e.g. np.random.seed(20) b) Define a user defined function func1 to accept the parameter to perform the sorting in ascending order. Then create an array E by invoking this function func1 with argument array D, so that elements in all columns are sorted vertically. (Hint: You may use np.sort in user defined function) (12 marks) 3) Write the Python codes to solve the following problems. Type print() to display the answer. a) Create an 36 array F from number 24 to 7 (including number 7 ). (5 marks) b) Split array F horizontally to obtain two arrays. Print them as array G1 and array G2. Then perform the summation of G1 and G2 to produce array H. Print array H with th following printout The summation of G1 and G2 is Array H\} c) Create a random matrix, I with shape 55 ), with elements of random values between 0 and 1. You can fix the random seed to 30 , by incorporating the following numpy command before generating the random number array I. Print array I with 3 decimal points. e.g. (7 marks) np.random.seed(30) Page 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started