Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

9.4 CHALLENGE: Array creation In the Challenge activity, create a number of arrays, following the specifications below. Problems 1. create the array pascal from the

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

9.4 CHALLENGE: Array creation In the Challenge activity, create a number of arrays, following the specifications below. Problems 1. create the array pascal from the numbers 1,1,1,1,2,1,1,3,3,1,1,4,6,4,1,1,5, 10, 10,5, 1 (see OEIS A007318). 2. create the array rebels from the list rebel_list = ['Leia', 'Luke', 'Han', 'Chewie'] 3. create the numpy array sigma_x corresponding to the Pauli matrix oz = 4. create a 4-dimensional array spacetime filled with zeros and 4 elements along the first axis, 2 elements along the second axis, 3, elements along the third axis, and 10 elements along the last axis. 5. create a numpy array u that contains the integers -10,-8,-7..., 9. 6. create a numpy array x that contains the numbers -10,-9.5, -9,-8.5,-8, -7.5, ..., 9,9.5 (steps of 0.5). 7.create an array y of 31 equally spaced values between -10 and 10 (inclusive). 8. create a function euler_phi(phi) which returns the rotation matrix cos sino 0 D= [Dij] = - sino cos 0 0 0 0 1 for a rotation around angle around the z-axis (also known as the first Euler angle rotation in the "x-convention") as a numpy array. Note: Define your function at the beginning of the main.py file (see the comments in the template). Otherwise the tests will not be able to find your function. (You can print output but there is no test that specifically looks at yor output. All tests directly test your variables and functions.) 282326.1742132 u (You can print output but there is no test that specifically looks at yor output. All tests directly test your variables and functions.) 282326.1742132 LAB ACTIVITY 9.4.1: CHALLENGE: Array creation 15/27 main.py Load default template... 1 import numpy as np 3 # create an array pascal from the given numbers 4 pascal = np.array([1,1,1,1,2,1,1,3,3,1,1,4,6,4,1,1,5,10,10,5,1]) 5 type(pascal) # create an array from the given list rebel_list = ['Leia', 'Luke', 'Han', 'Chewie'] 9 rebel_list = np.array(rebel_list) 10 typeCrebel_list) 11 12 # create a numpy array sigma_x 13 sigma_x = np.array([[0,1],[1,01]) 14 print(sigma_x) 15 type(sigma_x) 16 17 # create a 4-D array spacetime 18 spacetime = np. full(C4,2,3,10), 0) Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box Enter program input (optional) If your code requires input values, provide them here. Run program Input (from above) main.py (Your program) Output (shown below) (You can print output but there is no test that specifically looks at yor output. All tests directly test your variables and functions.) 282326.1742132 LAB ACTIVITY 9.4.1: CHALLENGE: Array creation 15/27 main.py Load default template... X 25 # create an array X 26 X = np.array([item for item in np.arange(-10,10,0.5)]) 27 28 29 # create an array y 30 y = np.array([item for item in np.arange(-10,10,0.65)]) 31 print("Number of elements in array y : ', len(y)) 32 y 33 34 34 # create a rotation matrix 35 def Ruler phi(phi): 26 36 mat = np.array(np.cos(phi), -np.sin(phi),0), (np.sin(phi), np.cos(phi),0), (0, 0, 1))) 37 return(mat) 29 38 39 # calling the fucntion 40 phi = 60 41 mat = euler_phi(phi) 42 mat Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Enter program input (optional) If your code requires input values, provide them here. Run program Input (from above) main.py (Your program) Output (shown below) 7: Unit test: y A 0/3 Your output [[O 1] [1 0]] Number of elements in array y : 31 Solution for y is not correct, see Arrays are not almost equal to 7 decimals Test feedback Mismatched elements: 30 / 31 (96.8%) Max absolute difference: 0.5 Max relative difference: 0.4 -9.35, x: array([-10. -8.7, -8.05, -7.4, -6.75, -6.1, -5.4 -4.8, -4.15, -3.5, -2.85, -2.2, -1.55, -0.25, -0.9, 0.4, 1.05, 1.7, 2.35, 3. 3.65, 4.3, 4.95, 5.6, 6.25, 6.9, 7.55, 8.2, 8.85, 9.5 ]) -9.3333333, -8.6666667, -8. 1 y: array([-10. -7.33333 -6.6666667, -6. -5.3333333 -4.6666667, -4. -3.3333333 -2.6666667, -2. -1.3333333, -0.6666667, - 8: Unit test: euler_phi( ^ 0/6 Your output [[0 1] [10]] Number of elements in array y : 31 Solution for euler_phi(1.5707963267948966) is not correct, see Arrays are not almost equal to 7 decimals Mismatched elements: 2 / 9 (22.2%) -3.3333333 -2.6666667, -2. -1.3333333 -0.6666667, - 8: Unit test: euler-phi( ^ 0/6 Your output [[O 1] [1 0] Number of elements in array y : 31 Solution for euler_phi(1.5707963267948966) is not correct, see Arrays are not almost equal to 7 decimals Test feedback Mismatched elements: 2 / 9 (22.2%) Max absolute difference: 2. Max relative difference: 2. x: array([[ 6.123234e-17, -1.000000e+00, 0.000000e+00], [ 1.000000e+00, 6.123234e-17, 0.000000e+00), [ 0.000000e+00, 0.000000e+00, 1.000000e+00]]) y: array([[ 6.123234e-17, 1.000000e+00, 0.000000e+00), [-1.000000e+00, 6.123234e-17, 0.000000e+00], [ 0.000000e+00, 0.000000e+00, 1.000000e+00]])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions