Only size-1 arrays can be converted to Python scalars

problem

only size-1 arrays can be converted to Python scalars

This comes out and the graph doesn't work well! !!

This is the source code of the problem

import matplotlib.pyplot as plt
import math
import np
x = np.linspace(0,1, 10000);
def y(a):
    return math.exp(a)
plt.figure(0)
plt.plot(x, y(x))
plt.show()

Cause

math functions can't handle matrices

Solved by using exp with numpy function

plt.plot(x, y(x))

Be careful because I'm throwing a line in this part

Therefore

def y(a):
    return np.exp(a)

If so, heal

Code after resolution

import matplotlib.pyplot as plt
import math
import numpy
x = np.linspace(0,1, 10000);
def y(a):
    return np.exp(a)
plt.figure(0)
plt.plot(x, y(x))
plt.show()

reference: https://blog.csdn.net/u013634684/article/details/49305655?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase

Recommended Posts

Only size-1 arrays can be converted to Python scalars
[Error] TypeError: only integer arrays with one element can be converted to an index
Have python check if the string can be converted / converted to int
Only size-1 arrays can be converted to Python scalars
[Error] TypeError: only integer arrays with one element can be converted to an index
Have python check if the string can be converted / converted to int
[Python] Why immutable int types can be changed to different values
[Python] Why immutable int types can be changed to different values
Python to remember only with hello, worlds
Only 8 Techniques to Pretend to be Data Scientists
If you want to make a Windows application (exe) that can be actually used now using only Python
I wanted to create a program in Reverse Polish Notation in Python (determining if a string can be converted to a number)
I want to create a priority queue that can be updated in Python (2.7)
When I try to use Jupiter notebook on Mac, I can only select python2
Python has come to be recognized so far.
3 steps to put Python + mecab in yum only
[Python] There seems to be something called __dict__
TypeError: can only concatenate str (not "float") to str
[Python] Introduction to web scraping | Summary of methods that can be used with webdriver
A mechanism to call a Ruby method from Python that can be done in 200 lines