x
in the following has the value:
[mpf('0.0') mpf('0.10000000000000001') mpf('0.20000000000000001')
mpf('0.30000000000000004') mpf('0.40000000000000002') mpf('0.5')
mpf('0.60000000000000009') mpf('0.70000000000000007')
mpf('0.80000000000000004') mpf('0.90000000000000002')]
code 1
import numpy as np
import mpmath as mp
import matplotlib.pyplot as plt
x = mp.arange(0,1,0.1)
y=x
plt.plot(x,y)
plt.show()
Everything is fine
code 2
import numpy as np
import mpmath as mp
import matplotlib.pyplot as plt
x = mp.arange(0,1,0.1)
y = 2.*x
plt.plot(x,y)
plt.show()
error occurs, says: can't multiply sequence by non-int of type 'float'. So in code 3 I change 2. to 2
code 3
import numpy as np
import mpmath as mp
import matplotlib.pyplot as plt
x = mp.arange(0,1,0.1)
y = 2*x
plt.plot(x,y)
plt.show()
It says this time: x and y must have same first dimension.
Finally, I found I can use np.array
to make x to be an array, all the trouble gone.
code 4
import numpy as np
import mpmath as mp
import matplotlib.pyplot as plt
x = mp.arange(0,1,0.1)
y = 2.*np.array(x)
plt.plot(x,y)
plt.show()
Can anyone explain to me, what does x
represents, what is mpf. why the above codes behave like that? If x is not an numerical array, why can it be used to plot? If it is an array, why can't it multiply by a number? I am so confused!