numpy "insert" 不插入任何东西
numpy "insert" does not insert anything
我在使用 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,所以我是初学者,但我有基础。
NumPy 的数组是不可变的(在大多数情况下),因此 np.insert
不会这样做 in-place,而是 returns 一个新数组,因此您需要:
arr = np.insert(arr,TheUserChoose ,theNewValue ) #note the arr =
我在使用 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,所以我是初学者,但我有基础。
NumPy 的数组是不可变的(在大多数情况下),因此 np.insert
不会这样做 in-place,而是 returns 一个新数组,因此您需要:
arr = np.insert(arr,TheUserChoose ,theNewValue ) #note the arr =