我正在嘗試查找二維數組的每一行的中位數。這是我到目前爲止所嘗試的,但我無法得到它的工作。任何幫助將不勝感激。查找二維數組的每一行的中位數
def median_rows(list):
for lineindex in range(len(Matrix)):
sorted(Matrix[lineindex])
mid_upper = ((len(Matrix[lineindex]))/2
mid_lower = ((len(Matrix[lineindex])+1)/2
if len(Matrix[lineindex])%2 == 0:
#have to take avg of middle two
median = (Matrix[mid_lower] + Matrix[mid_upper])/2.0
print "The median is %f" %median
else:
median = srtd[mid]
print "The median is %d" %median
median_rows(Matrix)