unity3d 如何将列标准化为平均值1

pinkon5k  于 2023-03-30  发布在  其他
关注(0)|答案(3)|浏览(143)

enter image description here以该列为例
我期望新列的平均值为1

q8l4jmvw

q8l4jmvw1#

import numpy as np

# assuming this is your data
data = np.array([2, 4, 6, 8, 10])

# calculate mean
mean = np.mean(data)

# divide each value by the mean
normalized_data = data / mean

# calculate the constant factor
factor = mean / np.mean(normalized_data)

# multiply each value by the factor
normalized_data = normalized_data * factor

print(normalized_data)
92dk7w1h

92dk7w1h2#

根据我对您的问题的理解,您希望新转换的列的均值为1。从每个点减去均值,然后加上1。

#x is your old column
#y is the transformed column

import numpy as np
x=np.random.normal(loc=50,scale=5,size=50)
print(np.mean(x)) #49.7593
y=[w-np.mean(x)+1 for w in x]
print(np.mean(y)) #0.9999
jjjwad0x

jjjwad0x3#

计算大小与总和的比率,并将其应用于所有值:

column = [0.91802, 0.42455, 1.194, -0.0638, 1.0975, 0.47269, 0.36525, 0.91995,
          0.65565, 1.2628, 1.6567, 1.7595, 1.1073, 1.9896, 1.1127, 0.51836,
          0.50849, 0.80634, 0.68905, 1.0065, 1.4413, 1.3735]

ratio    = len(column)/sum(column)
adjusted = [n*ratio for n in column]

print(adjusted)
print("average:",sum(adjusted)/len(adjusted))

[0.9519460594505549, 0.4402395367636142, 1.2381250898498537, 
-0.06615777280772249, 1.1380588660889568, 0.4901585835185321, 
0.37874806454577814, 0.9539473839257729, 0.679879995946446, 
1.309467641090783, 1.717924486058838, 1.8245235306455758, 
1.1482210318180426, 2.063127034141766, 1.1538205925259064, 
0.5375163497274457, 0.5272815971002949, 0.8361388483664413, 
0.7145143158802695, 1.0436958986045877, 1.4945642311562763, 
1.4242586356019882]

average: 1.0

相关问题