次の方法で、2の累乗と2を底とする対数のテーブルを生成しました。
import math
x = 2.0
while x < 100.0:
print x, '\t', math.log(x)/math.log(2)
x = x + x
各要素が1つのセルに完全に一致するCSVファイルでこのテーブルをエクスポートするにはどうすればよいですか?
https://docs.python.org/2/library/csv.html#csv.writerを参照してください
import math
import csv
x = 2.0
with open('out.csv', 'wb') as f:
writer = csv.writer(f, delimiter=',')
while x < 100.0:
print x, '\t', math.log(x)/math.log(2)
writer.writerow([x, math.log(x)/math.log(2)])
x = x + x
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加