TypeError with map with no len()
john polo
jpolo at mail.usf.edu
Mon Sep 25 12:44:19 EDT 2017
More information about the Python-list mailing list
Mon Sep 25 12:44:19 EDT 2017
- Previous message (by thread): Looking for an algorithm - calculate ingredients for a set of recipes
- Next message (by thread): TypeError with map with no len()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Python List, I am trying to make practice data for plotting purposes. I am using Python 3.6. The instructions I have are import matplotlib.pyplot as plt import math import numpy as np t = np.arange(0, 2.5, 0.1) y1 = map(math.sin, math.pi*t) plt.plot(t,y1) However, at this point, I get a TypeError that says object of type 'map' has no len() In [6]: t Out[6]: array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1, 2.2, 2.3, 2.4]) In [7]: y1 Out[7]: <map at 0x6927128> In [8]: math.pi*t Out[8]: array([ 0. , 0.31415927, 0.62831853, 0.9424778 , 1.25663706, 1.57079633, 1.88495559, 2.19911486, 2.51327412, 2.82743339, 3.14159265, 3.45575192, 3.76991118, 4.08407045, 4.39822972, 4.71238898, 5.02654825, 5.34070751, 5.65486678, 5.96902604, 6.28318531, 6.59734457, 6.91150384, 7.2256631 , 7.53982237]) At the start of creating y1, it appears there is an array to iterate through for the math.sin function used in map(), but y1 doesn't appear to be saving any values. I expected y1 to hold a math.sin() output for each item in math.pi*t, but it appears to be empty. Am I misunderstanding map()? Is there something else I should be doing instead to populate y1? John
- Previous message (by thread): Looking for an algorithm - calculate ingredients for a set of recipes
- Next message (by thread): TypeError with map with no len()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list