It's the code in the book 'Machine Learning in Action'. source code
And the what is passed to dataSet is a m * 3 array(datingTestSet2.txt which can be found in the superior directory. )
My question is:
What's the advantage of preparing a matrix to return? (conserve memory?)
If I don't prepare the matrix, will it go wrong? (It seems not.)
from numpy import *
def autoNorm(dataSet):
minVals = dataSet.min(0)
maxVals = dataSet.max(0)
ranges = maxVals - minVals
normDataSet = zeros(shape(dataSet)) # prepare matrix to return(It's my own comment, not in the source code. )
# Because there is a similar code before it,
# I think it should be the same meaning. Or any means else?
m = dataSet.shape[0]
normDataSet = dataSet - tile(minVals, (m,1))
normDataSet = normDataSet/tile(ranges, (m,1)) #element wise divide
return normDataSet, ranges, minVals