[英]Normalize an Array to Standard Normal Distribution
I think this is a pretty simple question but I wasn't able to find an answer. 我认为这是一个非常简单的问题,但我找不到答案。
I have an array: 我有一个数组:
array([ 62519, 261500, 1004836, ... , 0, 0])
I would like to convert it to a normal distribution with a min of 0 and a max of 1. 我想将其转换为最小值为0且最大值为1的正态分布。
Any suggestions? 有什么建议么? I was looking at sklearn.preprocess.normalize, but was unable to get it to work for me. 我正在查看sklearn.preprocess.normalize,但无法使其对我有效。
The purpose is that I am creating a scatterplot with numpy, and want to use this third variable to color each point. 目的是使用numpy创建散点图,并希望使用此第三个变量为每个点着色。 However, the colors have to be between 0 and 1, and because I have some weird outliers I figured a normal distribution would be a good start. 但是,颜色必须在0到1之间,并且由于我有一些怪异的异常值,我认为正态分布将是一个不错的开始。
Let me know if this doesn't make any sense. 让我知道这是否没有道理。 Thanks & Cheers. 谢谢与欢呼。
Oh I'm an idiot, I just wanted to standardize it and can just do z = (x- mean)/std
. 哦,我是个白痴,我只是想对其进行标准化,并且可以做到z = (x- mean)/std
。 Sorry. 抱歉。
I do not recommend using Standard Normal Distribution for normalization, please consider using frobenius/l2: 我不建议使用标准正态分布进行归一化,请考虑使用frobenius / l2:
normalized_z = z / np.linalg.norm(z)
normalized_z = z / math.sqrt(max(sum(z**2), 1e-12)) # L2: Matrix Norm
normalized_z = tf.nn.l2_normalize(z,0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.