你好,好人我在向陣列中插入日期時遇到了 Numpy python 庫的問題,這是我遇到問題的簡單代碼
import numpy as np
arr = np.array([]) # here is the array
UserInput = int(input("type the lenght of the array")) # the user decide the lenght of the array
arr.resize(UserInput)
#now if we print the array it will be [0,0,0,0,0,0...]
def inserting(): # simple function that let the user choose which index he/she want to change
...
TheUserChoose = int(input("choose the index that you want to change its value")) # now let's assume the user choose the index number '1'
theNewValue = int(input("type here")) # we type '7' okay
np.insert(arr,TheUserChoose ,theNewValue )
print(arr)
>>> [0,0,0,0,...0] Nothing change
# Also if I type the index and the value manually like "np.insert(arr,1 ,7)" nothing happened
我最近開始使用 python,所以我是初學者,但我有基礎知識
如果您看到任何英語錯誤,這是因為我不是以英語為母語的人
并認為你:]
uj5u.com熱心網友回復:
NumPy 的陣列是不可變的(在大多數情況下),因此np.insert不會就地執行,而是回傳一個新陣列,因此您需要:
arr = np.insert(arr,TheUserChoose ,theNewValue ) #note the arr =
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/468189.html
標籤:Python 数组 python-3.x 麻木的
