I am creating a GUI application using pyqt5. But I couldn't get the maximum value. Why this code prints the last row values instead of the maximum values.
Here is the code:
def submit(self):
rowCount = self.tableWidgetInput.rowCount()
columnCount = self.tableWidgetInput.columnCount()
if (rowCount==columnCount):
size=rowCount
print("The size of the matrxi is %d * %d "%(size,size))
print("The Given matrxi is", "SUM of Row" )
for row in range(size):
rowData =[]
for column in range (size):
widegetItem = self.tableWidgetInput.item(row,column)
if(widegetItem and widegetItem.text):
rowData.append(widegetItem.text())
else:
rowData.append('NULL')
inputArray =[]
inputArray = np.array(rowData,dtype=np.float64)
#sumofRow = np.sum(inputArray, axis = 0,dtype='float')
sumofRow = inputArray.sum(axis = 0,dtype='float')
maxInRows = np.amax(sumofRow,axis=0)
array_sum_max = max([np.sum(x,axis=0) for x in inputArray])
print(rowData, sumofRow)
print("The Maximum in the sum of row is " )
print( sumofRow )
else:
print("The input is not a Square matrix")
print("Data is not Submitted Sucessfully")
I want to find the sum or row then its maximum values in Pyqt5 table widget data using numpy.
Here is the output:
Size of the Matrix is Increased
The size of the matrxi is 3 * 3
The Given matrxi is SUM of Row
[5. 5. 5.] 15.0
[1. 1. 1.] 3.0
[2. 2. 2.] 6.0
The Maximum in the sum of row is
6.0
I think you rewrite the value of sumofRow. You could make another variable called max_sum for example and do something like:
if max_sum>=sumofRow:
max_sum = sumofRow
And in the end you could use that max_sum variable to get your maximum value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.