How to fix "TypeError: len() of unsized object"
<p>I am getting:</p>

<p><strong>TypeError: len() of unsized object</strong></p>

<p>after running the following script:</p>

<pre><code>from numpy import *

v=array(input('Introduce un vector v: '))
u=array(input('Introduce un vector u: '))

nv= len(v)
nu= len(u)

diferenza= 0; i=0

if nv==nu:

    while i&lt;nv:
        diferenza=diferenza + ((v[i+1]-u[i+1]))**2

    modulo= sqrt(diferenza)
    print('Distancia', v)
else:
    print('Vectores de diferente dimensiÃ³n')
</code></pre>

<p>How can I fix this?</p>

<p>Use the arrays' <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.size.html" rel="nofollow"><code>size</code></a> attribute instead:</p>

<pre><code>nv = v.size
nu = u.size
</code></pre>

<hr>

<p>You also probably want to use <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.fromstring.html#numpy.fromstring" rel="nofollow"><code>numpy.fromstring</code></a> to take and convert the input string into an array:</p>

<pre><code>&gt;&gt;&gt; v = np.fromstring(input('enter the elements of the vector separated by comma: '), dtype=int, sep=',')
enter the elements of the vector separated by comma: 1, 2, 3
&gt;&gt;&gt; v
array([1, 2, 3])
&gt;&gt;&gt; len(v)
3
&gt;&gt;&gt; v.size
3
</code></pre>

python arrays numpy