Rajesh Subramanian - 1 year ago 98

Python Question

i was trying to normalize a vector in python using numpy. I did the following:

`matrix_norm = numpy.linalg.norm(matrix1[:,0], ord='fro')`

print(matrix_norm)

The matrix1 is of size: 1000 X 1400. I tried find the normalization value for the first column of the matrix. And it gives me the following exception:

"Invalid norm order for vectors"

Please help !

Thanks in advance... :)

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

`ord='fro'`

is the Frobenius norm (https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.norm.html) and in numpy it is considered an invalid for vector norms (see https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.norm.html). If you want the 2-norm for vectors, just drop `ord`

:

```
norm_of_first_column = numpy.linalg.norm(matrix1[:,0])
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**