我是編程新手,幾乎不掌握術(shù)語,所以請原諒我可能遇到的任何基本問題。我正在嘗試列出數(shù)組的數(shù)組。我在二維數(shù)組上編寫了一個函數(shù),該函數(shù)列出了數(shù)組中的最高值及其出現(xiàn)的點(diǎn)。這些點(diǎn)(最大值)形成數(shù)組[i,j],為了便于顯示,我想將其收集到單個 numpy array 或 list 中max_p。據(jù)我所知,最明智的方法是使用numpy.append( max_p, [i,j] ). 問題在于它合并 [i,j])到max_p數(shù)組中,以便我得到單個值的數(shù)組而不是有序?qū)?。所以我決定將整個事情轉(zhuǎn)換成一個列表。在大多數(shù)情況下,這很有效——我得到了可以在一行中打印出來的有序?qū)α斜怼5?,大列表中的?shù)組max_p不會打印為,比如說[a,b]。它們被打印為array([a,b]). 無論我是否使用max_p.tolist()或 ,都會發(fā)生這種情況list(max_p)。當(dāng)然,如果沒有實際的代碼,這些都沒有意義,所以它是:def maxfinder_2D(array): maxima_array = numpy.array([]) # placeholder array for i in range(0, 422): # side note: learn how to get dim.s of # a multidimensional array x_array = array [i,:] # set array to be the i-th row # row_max = numpy.append(row_maxfinder_1D(x_array)) maxima_array = numpy.append(maxima_array, numpy.array([maxfinder_1D(x_array)])) # We construct a new array, maxima_array, to list the # maximum of every row in the plot. # The maximum, then, must be the maximum of this array. max_2D = maxfinder_1D(maxima_array) print("The maximum value in the image is: ", max_2D) global max_p max_p = [] # This gives us the maximum value. Finding its location is another # step, though I do wish I could come up with a way of finding the # location and the maximum in a single step.這是輸出(部分):The maximum value in the image is: 255.0 The function attains its maximum of 255.0 on [array([200., 191.]), array([200., 192.]), array([201., 190.]), array([201., 193.]), array([202., 190.]), array([202., 193.]), array([203., 193.]), array([204., 191.]),...我希望數(shù)組顯示為簡單的,例如[200. , 191.].為什么會出現(xiàn)這種“神器”呢?它與 numpy 如何將數(shù)組與列表相關(guān)聯(lián)嗎?
Python 3.7 - 打印 NumPy 數(shù)組列表會在實際數(shù)組前面打印“array”。為什么?
ibeautiful
2023-08-15 16:28:57