# A few Numpy Functions

Today I was taking the deep learning course from Udacity, they use numpy very often in that class and here are some notes about a few handy numpy functions that I learned.

# np.arange

arange is not a typo, it is simply a function very much like built-in range function but return a ndarray instead of list, that is probably why it is called a(rray)range. Here is the source code for arange in case you are interested.

```In : np.arange(-1, 1, 0.5)
Out: array([-1. , -0.5,  0. ,  0.5])```
```In : np.arange(12).reshape((3,4))

Out:
array([[ 0,  1,  2,  3],
[ 4,  5,  6,  7],
[ 8,  9, 10, 11]])```

# np.vstack

v(ertically)stack all the passed ndarray/list into a new array.

```In : np.vstack([[1,2], [3,4], [5,6], [7,8]])

Out:
array([[1, 2],
[3, 4],
[5, 6],
[7, 8]])
```

At the same time, you have other sibling utility functions like hstack, concatenate ..etc. that have a very similar usage.

```In : np.hstack([[1,2], [3,4], [5,6]])
Out: array([1, 2, 3, 4, 5, 6])```

# np.sum

the sum is pretty straight-forward, summing up all the numbers, however, there is one pitfall that I fell over is did not pay attention to the argument ‘axis‘. 0 means column wise and 1 means row wise.

```In : x

Out:
array([[ 0,  1,  2,  3],
[ 4,  5,  6,  7],
[ 8,  9, 10, 11]])

In : x.sum(0)

Out: array([12, 15, 18, 21])

In : x.sum(1)

Out: array([ 6, 22, 38])```