Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The language is Python 3. Please Help! If the pictures are hard to see, control+scroll to see them. I don't know why they are small.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedThe language is Python 3. Please Help! If the pictures are hard to see, control+scroll to see them. I don't know why they are small. thanks!

Problem 1 Given the list 1 and int n below, use a for loop to make a new list first_n that contains the first n values from the list 1. Your code should work for any value of n > 0. In the event that n is greater than the length of 1, the entire list I should be returned. In [ ]: 1 = [1, 2, 3, 4, 5, 7, 8] n = 4 In [ ]: # your code goes here, you can add more cells below this one if you need to Problem 2 Using the same list 1 from Problem 1 use a for loops to compute the mean (average) of 1 stored in a variable 1_avg . The correct answer is 4.286 for these values. Your code should work for any list with numerical values; you can't hard-code the length of 1 or any of its elements. In [ ]: # your code goes here, you can add more cells below this one if you need to Problem 3 Using the same list 1 from Problem 1 and 1_avg from problem 2. use a for loop to compute the variance)[https://en.wikipedia.org/wiki/Variance] of 1 . The variance is defined as the average of the square of the deviations from the mean. With the mean 4.286 in l_avg, the deviation of any value from the mean is value - l_avg. The average of these squares, the variance, is 5.63. Your code should work for any list with numerical values, you can't hard-code the length of 1 or any of its elements. In [ ] # your code goes here, you can add more cells below this one if you need to Problem 4 We can use lists of numbers like 1 to represent a mathematical vector. Recall from math classes that a vector is an object with a magnitude and direction. The magnitude is the sort of the sum of the squares (for a vector (x,y) it's the Pythagorean theorem for the magnitude (x^2 + y^2)^(1/2)). For a vector of any other length, the formula generalizes to (1[@]^2 + 1[1]^2 + 1[2]^2 + ... )^(1/2). For this problem use 1 from Problem 1 and a for loop to compute the magnitude of 1 with the result stored in 1_mag. For 1 above, its magnitude is 168. In [ ]: # your code goes here, you can add more cells below this one if you need to Problem 5 We will use vectors when we learn about the Vector Space Model (VSM) later We will need to compute the scalar or dot product of two vectors, which is defined for two vectors 1 = [x1, yi, z1] and m = [X2, y2, 22] as x1*x2 + yi*y2 + z1*22. For vectors that have a different number of elements, the formula is the sum of the product of corresponding elements 1[@]*m[@] + 1[1]*m[1] + 1[2] *m[2] + ... + 1[n]*m[n] where n+1 is the length of 1. For this problem use a for loop to compute the dot product of 1 and m below. The answer is . Your code should work for any two lists of equal length with all numerical values regardless of the length. For 1 and m below, the dot product is 4,940. In [ ] 1 = list(range (20)) list(range(0,40,2)) In [ ]: # your code goes here, you can add more cells below this one if you need to In [ ]

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_2

Step: 3

blur-text-image_3

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

please dont use chat gpt or other AI 2 9 5 . .

Answered: 1 week ago