Question: I'm relatively new to python but I'm trying to understand something which seems basic.

Create a vector:

```
x = np.linspace(0,2,3)
Out[38]: array([ 0.,  1.,  2.])

```

now why isn't x[:,0] a value argument?

```
IndexError: invalid index

```

It must be x[0]. I have a function I am calling which calculates:

```
np.sqrt(x[:,0]**2 + x[:,1]**2 + x[:,2]**2)

```

Why can't what I have just be true regardless of the input? It many other languages, it is independent of there being other rows in the array. Perhaps I misunderstand something fundamental - sorry if so. I'd like to avoid putting:

```
if len(x) == 1:
    norm = np.sqrt(x[0]**2 + x[1]**2 + x[2]**2)
else:
    norm = np.sqrt(x[:,0]**2 + x[:,1]**2 + x[:,2]**2)

```

everywhere. Surely there is a way around this... thanks.

Edit: An example of it working in another language is Matlab:

```
>> b = [1,2,3]
b =
     1     2     3 
>> b(:,1)
ans =
     1
>> b(1)
ans =

     1

```

Answer: 
Perhaps you are looking for this:

```
np.sqrt(x[...,0]**2 + x[...,1]**2 + x[...,2]**2)

```

There can be any number of dimensions in place of the ellipsis `...`

See also [What does the Python Ellipsis object do?](https://stackoverflow.com/q/772124/222914), and [the docs of NumPy basic slicing](http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#basic-slicing)
I tend to solve this is by writing

```
x = np.atleast_2d(x)
norm = np.sqrt(x[:,0]**2 + x[:,1]**2 + x[:,2]**2)

```

Matlab doesn't have 1D arrays, so `b=[1 2 3]` is still a 2D array and indexing with two dimensions makes sense. It can be a novel concept for you, but they're quite useful in fact (you can stop worrying whether you need to multiply by the transpose, insert a row or a column in another array...)

By the way, you could write a fancier, more general norm like this:

```
x = np.atleast_2d(x)
norm = np.sqrt((x**2).sum(axis=1))

```