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)
#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
3条答案
按热度按时间q8l4jmvw1#
92dk7w1h2#
根据我对您的问题的理解,您希望新转换的列的均值为1。从每个点减去均值,然后加上1。
jjjwad0x3#
计算大小与总和的比率,并将其应用于所有值: