【发布时间】:2021-03-12 10:47:33
【问题描述】:
我正在寻找创建一个随机维度的 numpy 数组,例如每 10 个迭代和替换值。
我试过了:
# Import numpy library
import numpy as np
def Iter_Replace(x):
print(x)
for i in range(x):
x[i] = 10
print(x)
def main():
x = np.array(([1,2,2], [1,4,3]))
Iter_Replace(x)
main()
但是我收到了这个错误:
TypeError: only integer scalar arrays can be converted to a scalar index
【问题讨论】:
-
如果
x是数组,range(x)没有意义。你想做什么? -
你好@hpaulj。 Cyttorak 明白我的问题。事实上,我想每 10 个替换数组中数组的所有值。