On 9/25/2017 5:37 PM, Thomas Jollans wrote:
On 25/09/17 18:44, john polo wrote:
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)
If you use np.sin instead of math.sin, you don't have to use map: Most
numpy functions operate elementwise on arrays (for example, you're
multiplying math.pi with an array - something that wouldn't work with a
list).

Here's the numpy way of doing this:

t = np.arange(0, 2.5, 0.1)
y1 = np.sin(np.pi * t)

Without using numpy at all, this might be

t = [i * 0.1 for i in range(25)]
y1 = [math.pi * a for a in t]
The numpy way looks like a great alternative. Thank you, Thomas.

John
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to