第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python 3.7 - 打印 NumPy 數(shù)組列表會在實際數(shù)組前面打印“array”。為什么?

Python 3.7 - 打印 NumPy 數(shù)組列表會在實際數(shù)組前面打印“array”。為什么?

ibeautiful 2023-08-15 16:28:57
我是編程新手,幾乎不掌握術(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)嗎?
查看完整描述

2 回答

?
素胚勾勒不出你

TA貢獻(xiàn)1827條經(jīng)驗 獲得超9個贊

Python對象有repr和str顯示方法


In [1]: x = np.arange(3)

In [2]: x

Out[2]: array([0, 1, 2])

In [3]: repr(x)

Out[3]: 'array([0, 1, 2])'

In [4]: str(x)

Out[4]: '[0 1 2]'

In [5]: print(x)

[0 1 2]

對于列表,它們[,]對于列表本身和repr元素是相同的:


In [6]: alist = [x]

In [7]: alist

Out[7]: [array([0, 1, 2])]

In [8]: repr(alist)

Out[8]: '[array([0, 1, 2])]'

In [9]: str(alist)

Out[9]: '[array([0, 1, 2])]'


查看完整回答
反對 回復(fù) 2023-08-15
?
白豬掌柜的

TA貢獻(xiàn)1893條經(jīng)驗 獲得超10個贊

也許您可以嘗試使用數(shù)組的字符串表示形式

print("The function attains its maximum of ",maxfinder_2D(img)," on ", np.array2string(max_p))


查看完整回答
反對 回復(fù) 2023-08-15
  • 2 回答
  • 0 關(guān)注
  • 167 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號