Wednesday, April 29, 2020

vector multiplication in machine learning using python

# add vectors
from numpy import array
a = array([1, 2, 3])
print(a)
b = array([1, 2, 3])
print(b)
c = a + b
print(c)
[1 2 3]
[1 2 3]
[2 4 6]
In [2]:
print(type(c))
<class 'numpy.ndarray'>
In [3]:
d=array([4,5,6])
e=array([1,2,3])
f=d-e
print(f)
[3 3 3]
In [4]:
g=a/b
print(g)
[1. 1. 1.]
In [5]:
#vector multiplication
h=d*e
print(h)
[ 4 10 18]
In [6]:
# vector-scalar multiplication
from numpy import array
a = array([1, 2, 3])
print(a)
s = 0.5
print(s)
c = s * a
print(c)
[1 2 3]
0.5
[0.5 1.  1.5]
In [ ]:
 

No comments:

Post a Comment

python class topic video