Question

IN PYTHON: Write a function that computes the outer product of two vectors WITHOUT using numpy /  inbuilt functions.

For example, the outer product of [1,2,3] x [1,2] is

outer product 2 1 2 3 2 4 6 2

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: I have completed answer for your question. Please check and let me know if you have any queries. I will get back to you within 24 hours. Thanks for your patience.

Code:
#!/usr/local/bin/python3


def out_prod(v1, v2):
   '''
       function which computes the vector product of two given vectors
   '''

   # setting the header here
   print('\nOuter Product')
   print('===============')
   print('i\k', end = ' ')
   for elem in v2:
       print("%5d" % elem, end = ' ')  

   # drawing the double line
   print('\n', '-'*25)
   print('\n')

   # calculating the outer product
   for elem1 in v1:
       print(elem1, end = ' ')
       for elem2 in v2:
           print("%5d" % (elem1 * elem2), end = ' ')
       print()


def main():
   out_prod([1,2,3], [1,2])
   out_prod([1,2], [1,2,3])
   out_prod([1,2,3],[1,2,3])

if __name__=='__main__':
   main()

Code screenshot:
#1 /usr/local/bin/python3 def out_prod(v1, v2): function which computes the vector product of two given vectors # setting theCode output screenshot:
Unix Terminal> python3 outer_prod.py Outer Product ilk 1 2 2 4 Outer Product ilk 1 2 3 4 Outer Product ilk 1 2 3 2 4 6 Unix T

Add a comment
Know the answer?
Add Answer to:
IN PYTHON: Write a function that computes the outer product of two vectors WITHOUT using numpy /&...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT