In [1]:
import numpy as np

In [9]:
x = np.array([1.,2.,3.])

In [10]:
x.sum()


Out[10]:
6.0

In [11]:
np.power(x, 2)


Out[11]:
array([ 1.,  4.,  9.])

In [12]:
def squared(i, n):
    return np.power(i, -1 * np.arange(1 , n + 1., 1))

In [14]:
x1 = squared(2, 3)

In [22]:
x2 = squared(10, 3)

In [23]:
x1


Out[23]:
array([ 0.5  ,  0.25 ,  0.125])

In [24]:
x2


Out[24]:
array([ 0.1  ,  0.01 ,  0.001])

In [25]:
def distance (x1, x2):
    y = x2 - x1
    z = np.power(y, 2)
    return np.sqrt(z.sum())

In [26]:
distance(x1, x2)


Out[26]:
0.48267587468196504

In [31]:
x = np.arange(2, 100, 1)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-31-ecdb8231cf9c> in <module>()
      1 x = np.arange(2, 100, 1)
----> 2 s = dist(2, 100)

NameError: name 'dist' is not defined

In [ ]: