def calculate(): # 计算每个数据点到每个中心点的欧氏距离 # 这里是将数据点都放入矩阵,直接按矩阵进行运算 reshape = ops.Reshape() tile = ops.Tile() reduce_sum = ops.ReduceSum(keep_dims=False) square = ops.Square() argmin = ops.Argmin() centroid_matrix = reshape(tile(centroids, (num_pts, 1)), (num_pts, k, num_feats)) point_matrix = reshape(tile(data_points, (1, k)), (num_pts, k, num_feats)) distances = reduce_sum(square(point_matrix - centroid_matrix), 2) centroid_group = argmin(distances) return centroid_group
def test_argmin_invalid_output_type(): P.Argmin(-1, mstype.int64) P.Argmin(-1, mstype.int32) with pytest.raises(TypeError): P.Argmin(-1, mstype.float32) with pytest.raises(TypeError): P.Argmin(-1, mstype.float64) with pytest.raises(TypeError): P.Argmin(-1, mstype.uint8) with pytest.raises(TypeError): P.Argmin(-1, mstype.bool_)
def __init__(self): super(ArgminNet, self).__init__() self.argmin = P.Argmin(axis=1)
'desc_bprop': [[1, 12, 1, 1]]}), ('DepthToSpace', { 'block': P.DepthToSpace(2), 'desc_inputs': [[1, 12, 1, 1]], 'desc_bprop': [[1, 3, 2, 2]]}), ('Split', { 'block': P.Split(1, 2), 'desc_inputs': [Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]]))], 'skip': ['backward']}), ('Argmax', { 'block': P.Argmax(), 'desc_inputs': [[128, 32, 32, 64]], 'desc_bprop': [0], 'skip': ['backward']}), ('Argmin', { 'block': P.Argmin(), 'desc_inputs': [[128, 32, 32, 64]], 'desc_bprop': [1], 'skip': ['backward']}), ('ArgMaxWithValue', { 'block': P.ArgMaxWithValue(), 'desc_inputs': [[128, 32, 32, 64]], 'desc_bprop': [[1], [1]], 'skip': ['backward']}), ('ArgMinWithValue', { 'block': P.ArgMinWithValue(), 'desc_inputs': [[128, 32, 32, 64]], 'desc_bprop': [[1], [1]], 'skip': ['backward']}), ('Transpose_dim3', { 'block': P.Transpose(),