0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

np.linspace, np.logspace, plt.plotの単引数での使用

Posted at

概要

基本的すぎるかもしれないが、numpyのlinspace(),logspace()の使い方を簡潔にまとめたかったのと、plt.plot()が単引数でも使えることに気づいたのでそれもメモする。

前提
import numpy as np
import matplotlib.pyplot as plt

環境

$ python --version
Python 3.10.0
$ pip freeze | grep numpy
numpy==1.22.4
$ pip freeze | grep matplotlib
japanize-matplotlib==1.1.3
matplotlib==3.5.2
matplotlib-inline==0.1.3

内容

等間隔データの作成

a = np.linspace(-3, 3)

なお、aは、${-3}$〜${3}$。

対数的に等間隔なデータの作成

b = np.logspace(-3, 3)

なお、bは、$10^{-3}$〜$10^{3}$。(base=で基底は変更できる)

Defaultの数は50

print(a.shape)  # (50,)
print(b.shape)  # (50,)

num=で総数を変更できる

a1000 = np.linspace(-3, 3, num=1000)
print(a1000.shape)  # (1000,)

plt.plot()は単引数でも可

plt.plot(b)
plt.show()

b.png

感想

linspaceが、linear space で、
logspaceが、logarithmic space であろうことは分かるのだけれど、
この場合のspace の訳語はなんなのだろう。

参考文献

0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?