python - Need to iterate through each column and find max and min -
import numpy np x = np.loadtxt('xdata.txt', dtype=float) y = np.loadtxt('ydata.txt', dtype=float) normalx = [] normaly = [] column in x: = 0 while <=17: xmax = max(column[i]) xmin = min(column[i]) normalx = (?-xmin)/(xmax-xmin) normalx.append(normalx) += 1 else: break
i have 148 17 matrix import , want normalize data. trying iterate through each column , find max , min code far results in "typeerror: 'numpy.float64' object not iterable". should ? if want have element in column.
instead of big 148x17 matrix ill put 4x4.
1.61 125 13 933.57 1.95 135 29 1357.77 1.91 135 28 1728 2.2 137 46 1828.05
first column max 2.2, min = 1.61 etc.
in code, first accessing for columns in x
causes columns
row
in x , later on inside loop trying access columns[i]
, return element in position in row.
you can use np.amax(x, axis=0)
maximum of each column , inturn return list of maximum each column.
similarly, can use np.amin(x, axis=0)
.
another issue if matrix of size 148x17
, in while
loop should checking till i<17
not i<=17
. can enumerate(column)
along for
loop same , syntax - for i, val in enumerate(column)
.
also, guessing need normalize values, need create list inside first loop , keep inserting list , @ end , add list normalx
.
example code -
xmax = np.amax(x, axis=0) xmin = np.amin(x, axis=0) column in x: tnormalx = [] i, val in enumerate(column): normalx = (val-xmin[i])/(xmax[i]-xmin[i]) tnormalx.append(normalx) += 1 normalx.append(tnormalx)
Comments
Post a Comment