I was practicing tesorflow
on Colaboratory and my code is as below.
There is some issue, the error message is
"TypeError: unsupported operand type(s) for +: 'map' and 'float'"
Can someone tell me what's wrong? thanks!
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(20)
y = map(lambda x: x + np.random.randn(1), x)
a, b = np.polyfit(x, y, 1)
plt.plot(x, y, 'o', np.arange(20), a*np.arange(20)+b, '-');**
the 'Colaboratory Introduction' is writed by Python2, as @cdarke said, map() return a map object in Python3. So you should trans the map obj to a list. Replace the code like this:
y = list(map(lambda x: x + np.random.randn(1), x))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With