0
0

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.

なぜfrom matplotlib import pyplot as pltではなく、import matplotlib.pyplot as pltなのか

Posted at

表題の疑問について

結論:import matplotlib.pyplot as pltとfrom matplotlib import pyplot as pltに違いはありません。
しかし、次のような場合は大きな違いが生まれます。

import numpy.random # 1
from numpy import random # 2

#1のコードはnumpyとnumpyの中のrandomモジュールがインポートされます。つまり下コードはエラーを吐きません。

import numpy.random

temp = numpy.array([0, 1, 2])

しかし、上記#2のコードはnumpyの中のランダムモジュールのみがインポートされるので、次のコードは

NameError: name 'numpy' is not defined

が出力されます。

0
0
0

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?