从for循环Python将数字列表打印为数组 [英] Printing list of numbers as an array from for loop Python

查看:65
本文介绍了从for循环Python将数字列表打印为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码,它一一打印相位"值.我正在尝试将这些值打印为for循环之外的数组.

With the code below, it prints the value 'phase' one by one. I am trying to print these values as an array outside of for loop.

import math

Period = 6.2

time1 = datafile1[:,0]
magnitude1 = datafile1[:,1]
for i in range(len(time1)):
   print(i,time1[i])
   floor = math.floor((time1[i]-time1[0])/Period)
   phase = ((time1[i]-time1[0])/Period)-floor 
   print (phase)

它是这样打印的:

0.002
0.003
0.004
0.005

我希望它像这样打印:

[0.002, 0.003, 0.004, 0.005]

推荐答案

这将是该结果的最少修改要求路径

This would be the least modification requirement path to that result

result = []

time1 = datafile1[:,0]
magnitude1 = datafile1[:,1]
for i in range(len(time1)):
   result.append(i,time1[i])
   floor = math.floor((time1[i]-time1[0])/Period)
   phase = ((time1[i]-time1[0])/Period)-floor 
   result.append(phase)

print(result)

这篇关于从for循环Python将数字列表打印为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆