簡體   English   中英

Numpy:從一個 numpy 數組中的每個元素減去 1

[英]Numpy: from a numpy array substract 1 to each element

我的 numpy 數組如下所示:

index_up = [   71    99   103 ... 24872 24892 24928]

我需要的:

index_up = [   70    98   102 ... 24871 24891 24927]

我試過了:

for e in index_up:
    e = e-1
    index_up[e] = e

但是沒有工作( index out of bounds )有什么想法嗎? 謝謝!

這是numpy的一個基本操作,你可以減去

index_up -= 1

文檔

使用以下代碼:

i=0
for e in index_up:
    e = e-1
    index_up[i]=e
    i+=1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM