Return the unit vector of a vector. Args: v: vector Returns: unit vector.
(v: NDArray[np.float64])
| 42 | |
| 43 | |
| 44 | def unit_vector(v: NDArray[np.float64]) -> NDArray[np.float64]: |
| 45 | """ |
| 46 | Return the unit vector of a vector. |
| 47 | |
| 48 | Args: |
| 49 | v: vector |
| 50 | |
| 51 | Returns: |
| 52 | unit vector. |
| 53 | """ |
| 54 | norm = np.linalg.norm(v) |
| 55 | return v if norm == 0 else v / norm |
no test coverage detected