python - python中 "for loop"的步骤

标签 python numpy import

我想根据循环中发生的变化来更改“for循环”的步骤。例如:

for i in np.arange(0,l00):
     i=i*10

在提到的代码中循环运行100次,而我希望i*10对循环产生影响并且它运行10次!你能指导我吗?

事实上,这只是一个简单的例子,但主要问题是改变循环中的步骤。像这样:

data = pd.read_csv('/home/Desktop/dataset.txt')    
for i in np.arange(0,l00):
     if data[i,0]==5:
         i=i*5
     elif data[i,0]==10:
         i=i*10
     else:
         i=i*20

最佳答案

RTFM numpy.arange ,这是第三个参数:

numpy.arange([start, ]stop, [step, ]dtype=None)

Parameters:

start : number, optional

Start of interval. The interval includes this value. The default start value is 0.

stop : number

End of interval. The interval does not include this value, except in some cases where step is not an integer and floating point round-off affects the length of out.

step : number, optional <<------- HERE

Spacing between values. For any output out, this is the distance between two adjacent values, out[i+1] - out[i]. The default step size is 1. If step is specified, start must also be given.

关于python - python中 "for loop"的步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33331233/

相关文章:

python - Scipy leastsq() 函数开销

python - 如何解释 : Label Ranking Average Precision Score

python - 如何在 Python 中结合以下理解?

python - 查找与给定向量相似的所有向量的快速方法

python - 如何从 python 脚本结果中删除 u''?

ios - 更新 RestKit 'lcl_RK.h' 文件未在 RKLog.h 中找到

java - 如何导入多行csv文件?

ios - 导入应用程序后保存文件

python - 添加具有不同标签和不同维度的矩阵

python - 为什么 Python 逻辑并不总是计算为 bool 值?