#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 18 11:33:51 2021
@author: xiaokangyu
"""
import numpy
import numpy as np
def normalize_rows(x: numpy.ndarray):
"""
function that normalizes each row of the matrix x to have unit length.
Args:
``x``: A numpy matrix of shape (n, m)
Returns:
``x``: The normalized (by row) numpy matrix.
"""
return(x/numpy.linalg.norm(x, ord=2, axis=1, keepdims=True))
x=np.array([[1,1,2],[2,2,2]])
print(normalize_rows(x))
行单位化数据
最新推荐文章于 2023-01-20 22:11:27 发布