Neha
Neha

Reputation: 19

how to take sum of two 1-D array(column vector)

I wanted to add two 5 X 1 column vector. But I am getting error: Invalid syntax

def sumg():
    w = np.ones((5,1))
    s = 1
    g=0
    b = np.random.rand(5,1)
    g = b + np.multiply(s,w)
 return(g)

I expect the output to return b+s*w

Upvotes: 0

Views: 8001

Answers (1)

mahbubcseju
mahbubcseju

Reputation: 2290

You should import numpy and indent the return statement correctly. like

import numpy as np
def sumg():
    w = np.ones((5,1))
    s = 1
    g=0
    b = np.random.rand(5,1)
    g = b + np.multiply(s,w)
    return(g)

return(g) should start where g start from .Hope it will help.

Upvotes: 1

Related Questions