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 5 years have passed since last update.

今日のpython error TypeError: only length-1 arrays can be converted to Python scalars

Posted at

プログラムちょい替え(6)pyhon sin 描画
https://qiita.com/kaizen_nagoya/items/2702bdf0b89b3d841921

で、さらに直そうとして次のようなプログラムにしてみた。

sina.py
import matplotlib.pyplot as plt
import numpy as np
import math 

# データ生成
x = np.linspace(0, 3.2, 10)
y = math.sin(x)

# プロット領域(Figure, Axes)の初期化
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(133)

# 棒グラフの作成
ax.scatter( x, y)

# 水平線、垂直線を入れる
ax.axhline(0)

plt.show()

実行してみる。

macOS
$ python sin.py
Traceback (most recent call last):
  File "sin.py", line 7, in <module>
    y = math.sin(x)
TypeError: only length-1 arrays can be converted to Python scalars

ごめん。

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?