Question

In: Computer Science

This is a question about coding in python. I think that the question is asking me...

This is a question about coding in python. I think that the question is asking me to code the following: Implement the scalar product of 2 vectors in 2-space, using two tuple parameters (the function scalarProduct2). Write a docstring; then write some test function calls (can I pick any data for this? - the question gave these examples data examples: (1., 1.) dot (2,3) = (1.,1.) dot (2,0) = (1., 1.) dot (0,2) = (1., 1.,) dot (4,5) = ); then implement the body of the function ( I am not sure what this means - run the function?)

Solutions

Expert Solution

Thanks for the question.


Here is the completed code for this problem

Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please rate the answer.

Thanks


===========================================================================

Here is the formula to compute the scalar product of two vectors a and b

def scalarProduct(vectorOne, vectorTwo):
    # first check the element count in both the tuples are same
    # if they are same only then we proceed to find the scalar product
    if len(vectorOne) == len(vectorTwo):

        scalar_product = 0
        # iterate over each element of the two tuples
        for i in range(len(vectorTwo)):
            # multiply the elements at the same index
            # and add it to the scalar_product variable
            scalar_product += vectorOne[i] * vectorTwo[i]
        # return the value
        return scalar_product
    else:
        # incase the element counts are not same
        print('The dimensions of the two vectors are different. Cannot compute scalar product.')


def main():
    # create 3 tuples assuming they are vectors
    v_one = (1., 1.)
    v_two = (2., 3.)
    v_three = (4, 5)

    print('Scalar Product is: {}'.format(scalarProduct(v_one, v_two)))
    print('Scalar Product is: {}'.format(scalarProduct(v_one, v_three)))
    print('Scalar Product is: {}'.format(scalarProduct(v_three, v_two)))


main()


Related Solutions

This is Python coding question, and topic is loop Can anyone help me figuring these out?...
This is Python coding question, and topic is loop Can anyone help me figuring these out? (Please do not use build in function) Thanks. 1. Write a program that prints your name 100 times to the screen. 2. Write a program that takes a string s and an integer n as parameters and prints the string s a total of in n times(once per line) 3. Write a for loop that prints all the integers from 3141 to 5926, skipping...
I have a python coding question: Write the function: eAapproximately (n), that takes a positive integer...
I have a python coding question: Write the function: eAapproximately (n), that takes a positive integer value n and returns an approximation of e as (1 + 1/n)^n I am not even sure what the question is asking me to do but I think it is asking me to code that function. Does anyone know how to do this?
1. I am interested in asking people what they think about the current election and who...
1. I am interested in asking people what they think about the current election and who their favorite candiate is. I decide to go to random subdivisons and city blocks and ask 15 people from each region who their favorite candiate is. I decide to go to random subdivisons and city blocks and ask 15 people from each region who their favorite candiate is. This is an example of: a. Stratified sampling b. Simple Random Sampling c. Systematic Sampling. d....
I am in this electrical engineering project course in which an assignment is asking me this...
I am in this electrical engineering project course in which an assignment is asking me this and I cannot make heads or tails of what it means by this... Discuss the tradeoffs involved between using patents and trade secrets to protect intellectual property. Please be as descriptive as possible, THANKS
note: this is the first time asking a question, I know this isn't a physcology question,...
note: this is the first time asking a question, I know this isn't a physcology question, but that was the only "subject" under social sciences that came anywhere near to the topic. is that what I should have done? James Madison, in the Federalist Papers, argued that “factions” (interest groups) will balance out and neutralize each other across topics, geographic regions, interests, incomes, ethnic and religious backgrounds, and so on. Thus, no single or no few groups will dominate. In...
Using python coding, test for convergence of an infinite sequence or series. keep the coding at...
Using python coding, test for convergence of an infinite sequence or series. keep the coding at beginner level please!
I am not quite sure what this question is asking, nor do I understand how to...
I am not quite sure what this question is asking, nor do I understand how to apply the lower-of-cost-or-NRV. The controller of Alt Company is applying the lower-of-cost-or-net realizable value basis of valuing its ending inventory. The following information is available: Cost Net Realizable Value Lawnmowers: Self-propelled $14,800 $17,000 Push type 19,000 18,000 Total 33,800 35,000 Snowblowers: Manual 29,800 31,000 Self-start 19,000 21,000 Total 48,800 52,000 Total inventory $82,600 $87,000 Compute the value of the ending inventory by applying the...
Write a response commenting on their report and asking a question about the report, including questions...
Write a response commenting on their report and asking a question about the report, including questions about the scientists who performed the research and the organisms under discussion. Please make sure to answer all questions in reply to your report in detail. 1st comment A brief summary of the ethical concerns surrounding this topic. Designer babies is the idea of creating babies with disease free and super authentic or smart by using technology to manipulate genetic. In fact, parents can...
I cannot get this code to run on my python compiler. It gives me an expected...
I cannot get this code to run on my python compiler. It gives me an expected an indent block message. I do not know what is going on. #ask why this is now happenning. (Create employee description) class employee: def__init__(self, name, employee_id, department, title): self.name = name self.employee_id = employee_id self.department = department self.title = title def __str__(self): return '{} , id={}, is in {} and is a {}.'.format(self.name, self.employee_id, self.department, self.title)    def main(): # Create employee list emp1...
Python: I am not sure where to begin with this question, and I hope I can...
Python: I am not sure where to begin with this question, and I hope I can get an input on it. This is in regards to Downey's program, and we are asked to make two changes. Downey prints time as they do in the Army: 17:30:00 hours. We want to print that as 5:30 PM. Downey lets you define the time 25:00:00 - we want to turn over at 23:59:59 to 00:00:00. (I am asked to identify my changes with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT