gpt4 book ai didi

r - Octave/Matlab 中的scale() R 函数等效项

转载 作者:行者123 更新时间:2023-12-02 21:02:58 25 4
gpt4 key购买 nike

为了避免循环,有没有一种方法可以将数据矩阵围绕列(或行)的平均值居中,并按标准差(也可以按列或按行)缩放每个条目?

在 R 中这很简单:scale(data, center = T,scale = T))

但我不知道如何在 Ocatave 或 Matlab 中实现相同的基本预处理。

最佳答案

在 Octave 中,有两个函数分别用于 center() 和 zscore()。 center 只是减去平均值,而 zscore 还除以 sd(有时称为标准化的操作)

center (x)

Center data by subtracting its mean.

If x is a vector, subtract its mean. If x is a matrix, do the above for each column. If the optional argument dim is given, operate along this dimension.

zscore (x, opt, dim) Computes the Z score of x

if x is a vector, subtract its mean and divide by its standard deviation. If the standard deviation is zero, divide by 1 instead.

The optional parameter opt determines the normalization to use when computing the standard deviation and has the same definition as the corresponding parameter for std.

If x is a matrix, calculate along the first non-singleton dimension. If the third optional argument dim is given, operate along this dimension.

关于r - Octave/Matlab 中的scale() R 函数等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37378168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com