sciPy stats.zmap() function | Python
Last Updated :
20 Feb, 2019
scipy.stats.zmap(scores, compare, axis=0, ddof=0) function computes the relative Z-score of the input data. The scores that are standardized to zero mean and unit variance, where mean and variance are calculated from the comparison array.
Its formula:
Parameters :
scores : [array_like]Input array or object for which Z-score is to calculate.
compare : [array_like]Input array or object for which the mean and standard deviation of the normalization are taken
axis : Axis along which the mean is to be computed. By default axis = 0.
ddof : Degree of freedom correction for Standard Deviation.
Results : Z-score of the input data.
Code #1: Working
import numpy as np
from scipy import stats
arr1 = [[ 20 , 2 , 7 , 1 , 34 ],
[ 50 , 12 , 12 , 34 , 4 ]]
arr2 = [[ 50 , 12 , 12 , 34 , 4 ],
[ 12 , 11 , 10 , 34 , 21 ]]
print ( "\narr1 : " , arr1)
print ( "\narr2 : " , arr2)
print ( "\nZ-score : \n" , stats.zmap(arr1, arr2))
|
Output :
arr1 : [[20, 2, 7, 1, 34], [50, 12, 12, 34, 4]]
arr2 : [[50, 12, 12, 34, 4], [12, 11, 10, 34, 21]]
Z-score :
[[ -0.57894737 -19. -4. -inf 2.52941176]
[ 1. 1. 1. nan -1. ]]
Code #2 : Z-score
import numpy as np
from scipy import stats
arr1 = [[ 20 , 2 , 7 , 1 , 34 ],
[ 50 , 12 , 12 , 34 , 4 ]]
arr2 = [[ 50 , 12 , 12 , 34 , 4 ],
[ 12 , 11 , 10 , 34 , 21 ]]
print ( "\nZ-score : \n" , stats.zmap(arr1, arr2, axis = 1 ))
|
Output :
sem ratio for arr1 :
[[-0.14087457 -1.19743386 -0.90394517 -1.2561316 0.68089376]
[ 3.5640998 -0.61601725 -0.61601725 1.80405051 -1.49604189]]
Share your thoughts in the comments
Please Login to comment...