The result will be different from the result you should have.Please tell me about "nan".

Asked 2 years ago, Updated 2 years ago, 45 views

I started studying recently.I'd like to display a three-dimensional graph in a two-dimensional array, but somehow it says nan.
Please let me know if anyone knows.

src=

python python3 numpy

2022-09-30 10:26

1 Answers

The f3 function has no return value, so no value is assigned and becomes nan.
Add return answer to the end of the function to assign a value.

import numpy as np
import matplotlib.pyplot asplt

def3(x0,x1):
    r=2*x0**2+x1**2
    an=r*np.exp(-r)
    returnans# Add this line

xn = 9
x0 = np.linspace (-2,2,xn)
x1 = np.linspace (-2,2,xn)
y=np.zeros(len(x0),len(x1))))
for i0 in range (xn):
    for i1 in range (xn):
      y[i1, i0] = f3 (x0[i0], x1[i1])

print(x0)
print(np.round(y,1))

If you ask questions, it would be easier to get answers if you put the source code instead of the screenshot so that it is reviewable sample code.


2022-09-30 10:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.