Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
enumeration code help
#6
For later use, you should look for numpy.
This allows for example broadcasting.

import numpy as np


def gen_signal():
    amplification = 10.5
    time_base = np.linspace(0, np.pi * 2, 1_000_000)
    signal = np.sin(time_base * 1440) # 1440 Hz
    signal += np.sin(time_base * 440) # 440 Hz
    signal += np.sin(time_base * 20) # 20 Hz
    signal += np.sin(time_base * 44) # 44 Hz
    signal *= amplification
    return signal
But you should also know the Python primitives.
I see often, that people are using this libraries,
but they don't know how they can do this without this library.

The benefit of numpy is, that it's implementation is in C and highly optimized.
But for small lists it's ok to use a normal list comprehension or if you want to save memory, a generator expression.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
enumeration code help - by sar - Jan-22-2019, 04:56 PM
RE: enumeration code help - by ichabod801 - Jan-22-2019, 05:14 PM
RE: enumeration code help - by nilamo - Jan-22-2019, 05:14 PM
RE: enumeration code help - by perfringo - Jan-22-2019, 05:15 PM
RE: enumeration code help - by sar - Jan-22-2019, 05:50 PM
RE: enumeration code help - by DeaD_EyE - Jan-22-2019, 06:30 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020