import numpy as np, matplotlib.pyplot as plt
from scipy.fftpack import rfft, irfft
n = 2 ** 8
x = np.linspace(0, 2 * np.pi, n)
y = np.sin(x) + np.cos(x * 30)
f0 = rfft(y)
f1 = f0.copy()
f1[:n // 8] = 0
z = irfft(f1)
f, (spectra, signal) = plt.subplots(2, 1, sharey=False)
spectra.plot(x, f0, label='f0')
spectra.plot(x, f1, label='f1')
spectra.legend()
spectra.title.set_text('spectra')
signal.plot(x, y, label='y')
signal.plot(x, z, label='z')
signal.legend()
signal.title.set_text('signal')
plt.legend()
plt.show()
print(('No', 'Yes')[p >= abs(v) + abs(w) and not (p + v + w) % 2])
Сорок да сорок - рубль сорок,
Спички брали - Нет - С вас два рубля.
Так не брал же!
Если б брали - было б шесть.
def f(n):
return 0 if n == 1 else f(n - 1) * n + n
print(f(20)) # 4180411311071440000
import re
from collections import Counter
with open('maillog', 'r') as fi:
for m, n in Counter(re.findall(r'(?<=\bfrom=<)[^>]+', fi.read(),
flags=re.M)).most_common():
print(f'{m:32}{n:>3}')
center_y = y + h // 2
dh = max(min(h // 10, center_y - h * 3 // 5, image.height - center_y - h * 3 // 5), 0)
new_y, new_h = y - dh, h + 2 * dh
import asyncio, warnings, itertools
def a():
for ch in 'foo':
print(ch, 'from a')
yield
@asyncio.coroutine
def b():
for ch in 'foo':
print(ch, 'from b')
yield
async def c():
for ch in 'foo':
print(ch, 'from c')
await asyncio.sleep(0)
print('как ни странно, здесь все три прокатывают\n')
loop = asyncio.get_event_loop()
tasks = [loop.create_task(f()) for f in (a, b, c)]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()
print('\nмежду тем, есть нюансы\n')
with warnings.catch_warnings():
warnings.simplefilter('ignore')
dirs = [[*dir(f), *dir(f())] for f in (a, b, c)]
for s in sorted(set(itertools.chain(*dirs))):
if not all(s in d for d in dirs):
print(f'{s:14}', *['-+'[s in d] for d in dirs])