Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8611381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:21:42+00:00 2026-06-12T04:21:42+00:00

I have my first task on python class: Create a module vectors.py It will

  • 0

I have my first task on python class:

  • Create a module vectors.py
  • It will be a class definition MyVector
  • constructor will accept one parameter, which will be one-dimensional array.
  • get_vector() method returns one-dimensional array containing the elements of the vector.
  • using a special method __ mul__(self, other) implement the dot product of two objects of type MyVector. The output is a scalar (a single number).

Now it’s seems like this:

class MyVector:
    def __init__(self,vector=[]):
        self.vector=vector

    def get_vector(self):
        return (self.vector)        

    def __mul__(self,other):
        dot=sum(p*q for p,q in zip(self.vector, WHAT IS HERE?))
        return(dot)

I have first vector, but how can I initialize second?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:21:43+00:00Added an answer on June 12, 2026 at 4:21 am

    If you assume that the other parameter for the special __mul__ method is an instance of MyVector, then that instance will also have an attribute named vector which you can access:

    def __mul__(self,other):
        dot=sum(p*q for p,q in zip(self.vector, other.vector))
        return (dot)
    

    and don’t use [] as default value in function arguments, use something like this :

     def __init__(self,vector=None):
        self.vector=vector if vector else []
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a task in Python and i run this task for first time
I have a quick one off task in a python script that I'd like
I would like to have this behavior in a task history stack: First task
my first time posting. I have a tricky task of finding the latest date
I have first names stored in one table and last names stored in another.
I have a custom c++ module for python that exposes functions, some of which
I have some python scripts that configure linux computers. One of the tasks is
I was recently trying to solve some task in Python and I have found
If I have two objects Project and Task associated with one-to-many relation Project.hasMany(Task) var
I have first: select url from urls where site = '$value' order by url

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.