Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5.1 Basic list and array operations 1. Create a list that has the contents: 6, 8*3, 2.5, 'labtime' and v2. When creating a list or

image text in transcribedimage text in transcribed

5.1 Basic list and array operations 1. Create a list that has the contents: 6, 8*3, 2.5, 'labtime' and v2. When creating a list or array always print out result for validation a) Use a list method to find the index of 'labtime' b) Use another list method to add the contents of the list (3,1,4,15,6] to your list. c) remove the element with value 15 from the list 2. Create a vector in which the first element is O, and the last element is 42, with an increment of 3 between the elements (0, 3, 6, ......, 42). Use a python function to do this. 3. Create a vector in which the first element is 18, the elements decrease with increments of -4.5, and the last element is -18. 4. Create a list with 16 equally spaced elements in which the first element is 5 and the last element is 61. 5. a) Create two character strings, 'name' and 'name2', containing your first and last names. b) Create a third string variable by concatenating the first two strings, along with an appropriate space. 6. a) Create a vector, named 'Afirst, that has 13 elements in which the first is 3, the increment is 4 and the last element is 51. b) Create a new vector, named 'Asecond', that has seven elements (do this step first). The first four elements of Asecond are the first four elements of Afirst and the last three elements of Asecond are the last three elements of Afirst. 1. Create an array w with values 0, 0.1, 0.2, ..., 3. Print the following: w[:], w[:-2], w[::5), w[2:-2:6]. Explain in each case the elements of the array that are being printed. 2. Create a 5-element vector, and a 2 x 3 array, with names and values of your choosing. Inspect their properties using type(), whos, len(), shape(), and size(). Report the results and comment on what they mean. 3. Create a vector, try out the following built-in functions on it, and comment on what they do: len(), min(), max(), sum(), sorted(), sort() 4. Create the matrix shown below by using vector notation for creating vectors with constant spacing and/or the linspace command when entering the rows. Use np.concatenate and np.reshape (look up how these function/methods work) to turn 1D array into 2D. 0 4 8 12 16 20 24 28 B = 69 68 67 66 65 64 63 62 (1.4 1.1 0.8 0.5 0.2 -0.1 -0.4 -0.7/ 5. Replace the fourth column in matrix B with the numbers 1 to 3. 6. a) Create a 2x5 matrix called msame with all the elements are the number 7. b) Add a third row of zeros and then a fourth row with numbers 1 to 5 c) Add a fifth row that multiplies the second row by the number 6. d) Concatenate the matrix B with the middle three rows of msame 7. Evaluate the dot product of two vectors, using vectorization to do so in just one line of code, where the dot product is: = ; 5.1 Basic list and array operations 1. Create a list that has the contents: 6, 8*3, 2.5, 'labtime' and v2. When creating a list or array always print out result for validation a) Use a list method to find the index of 'labtime' b) Use another list method to add the contents of the list (3,1,4,15,6] to your list. c) remove the element with value 15 from the list 2. Create a vector in which the first element is O, and the last element is 42, with an increment of 3 between the elements (0, 3, 6, ......, 42). Use a python function to do this. 3. Create a vector in which the first element is 18, the elements decrease with increments of -4.5, and the last element is -18. 4. Create a list with 16 equally spaced elements in which the first element is 5 and the last element is 61. 5. a) Create two character strings, 'name' and 'name2', containing your first and last names. b) Create a third string variable by concatenating the first two strings, along with an appropriate space. 6. a) Create a vector, named 'Afirst, that has 13 elements in which the first is 3, the increment is 4 and the last element is 51. b) Create a new vector, named 'Asecond', that has seven elements (do this step first). The first four elements of Asecond are the first four elements of Afirst and the last three elements of Asecond are the last three elements of Afirst. 1. Create an array w with values 0, 0.1, 0.2, ..., 3. Print the following: w[:], w[:-2], w[::5), w[2:-2:6]. Explain in each case the elements of the array that are being printed. 2. Create a 5-element vector, and a 2 x 3 array, with names and values of your choosing. Inspect their properties using type(), whos, len(), shape(), and size(). Report the results and comment on what they mean. 3. Create a vector, try out the following built-in functions on it, and comment on what they do: len(), min(), max(), sum(), sorted(), sort() 4. Create the matrix shown below by using vector notation for creating vectors with constant spacing and/or the linspace command when entering the rows. Use np.concatenate and np.reshape (look up how these function/methods work) to turn 1D array into 2D. 0 4 8 12 16 20 24 28 B = 69 68 67 66 65 64 63 62 (1.4 1.1 0.8 0.5 0.2 -0.1 -0.4 -0.7/ 5. Replace the fourth column in matrix B with the numbers 1 to 3. 6. a) Create a 2x5 matrix called msame with all the elements are the number 7. b) Add a third row of zeros and then a fourth row with numbers 1 to 5 c) Add a fifth row that multiplies the second row by the number 6. d) Concatenate the matrix B with the middle three rows of msame 7. Evaluate the dot product of two vectors, using vectorization to do so in just one line of code, where the dot product is: =

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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions