import numpy as np
x = np.linspace(0, 1, 2)
y = np.linspace(0, 1, 3)
X1, Y1 = np.meshgrid(x, y)
X2, Y2 = np.meshgrid(x, y, sparse=True)
print(*X1.shape, *Y1.shape, *X2.shape, *Y2.shape)
Добро пожаловать на канал "Задачи по Python и машинному обучению"! Если вы интересуетесь программированием на Python и хотите изучить алгоритмы, функции, классы, регулярные выражения, итераторы, генераторы, ООП, исключения, а также более сложные темы вроде numpy, pandas и scikit-learn, то этот канал - для вас. Здесь вы найдете множество задач и упражнений, которые помогут вам улучшить свои навыки в программировании и машинном обучении. Мы также предлагаем рекламные возможности на нашем канале - посетите ссылку 'https://payment-it.ru' для получения дополнительной информации. Присоединяйтесь к нам, чтобы узнать больше о мире программирования и машинного обучения! Для любых вопросов обращайтесь к администратору канала - @advertmng.
10 Jan, 09:00
import numpy as np
x = np.linspace(0, 1, 2)
y = np.linspace(0, 1, 3)
X1, Y1 = np.meshgrid(x, y)
X2, Y2 = np.meshgrid(x, y, sparse=True)
print(*X1.shape, *Y1.shape, *X2.shape, *Y2.shape)
09 Jan, 09:00
import numpy as np
x = np.linspace(0, 2, 3)
y = np.linspace(0, 1, 2)
X, Y = np.meshgrid(x, y)
print(int(X.sum()), int(Y.sum()))
08 Jan, 09:00
import numpy as np
a = np.arange(4).reshape(2, 2)
b = a[:, np.newaxis, :]
print(b.shape)
07 Jan, 09:00
import numpy as np
np.newaxis is None
06 Jan, 09:00
import numpy as np
vals = np.arange(1, 10)
bools = (vals % 2 == 0) | (vals % 3 == 0) & ~(vals % 9 == 0)
print(vals[bools])
03 Jan, 09:00
import numpy as np
a = np.array([1, 2, 3])
ia = np.array([True >> 0, False, True])
print(a[ia].sum())
02 Jan, 09:00
import numpy as np
a = np.array([3, 1, 2])
ia = np.array([True, False, True])
print(a[ia].sum())
01 Jan, 09:00
import numpy as np
a = np.arange(6).reshape(3, 2)
ia = np.array(((0, 0), (0, 1)))
ja = np.array(((1, 0), (0, 0)))
b = a[ia, ja]
print(b.sum() + b.ndim + b.size)
30 Dec, 09:00
import numpy as np
a = np.array([[1, 3], [5, 7]])
a[:, 0] = 0
a[1, :] = 1
print(a.sum())
26 Dec, 09:00
import numpy as np
a = np.array([1, 2, 3, 4, 5])
b = a[[0, 1, 2]]
c = a[0:3]
b[0] = -1
c[1] = -1
print(a[0], a[1])
25 Dec, 09:00
import numpy as np
a = np.arange(8).reshape((2, 2, 2))
x = np.dsplit(a, 2)[0].sum()
print(x)
24 Dec, 09:00
import numpy as np
a = np.arange(6)
a = a.reshape(-1, 1)
x = np.vsplit(a, 2)[-1].sum()
print(x)
23 Dec, 09:00
import numpy as np
a = np.arange(4)
x = np.hsplit(a, 2)[0]
print(x.sum())
20 Dec, 09:00
import numpy as np
a = np.array([1, 2])
b = np.array([3, 4])
c = np.dstack((a, b))
print(c.shape)
19 Dec, 09:00
import numpy as np
a = np.array([1, 2])
b = np.array([3, 4])
c = np.vstack((a, b))
print(c.shape)
18 Dec, 09:00
import numpy as np
a = np.array([1, 2])
b = np.array([3, 4])
c = np.hstack((a, b))
print(c.shape)
17 Dec, 09:00
import numpy as np
a = np.arange(4)
b = a.transpose()
x = a.shape == b.shape
print(x)
16 Dec, 09:00
import numpy as np
a = np.linspace(1, 4, 4)
b = a.reshape(2, 2)
b[0, 0] = 0
print(a[0] + b[0, 0] + b[1, 1])
13 Dec, 09:00
import numpy as np
a = np.linspace(1, 4, 4)
# ваш код
print(a)
29 Nov, 09:00
import numpy as np
a = np.array(((1, 0, 1), (0, 1, 0)))
print(a.ndim)
28 Nov, 09:00
import numpy as np
a = np.array(((1, 0, 1), (0, 1, 0)))
print(a.shape)
27 Nov, 09:00
import numpy as np
x = np.fromfunction(lambda i, j: 2 * i * j, (3, 3), dtype=int)
y = np.sum(x[1])
print(y)
26 Nov, 09:00
def f(i, j):
return i * j
x = np.fromfunction(f, (3, 3), dtype=int)
y = np.sum(x)
print(y)
25 Nov, 09:00
import numpy as np
x = np.linspace(0, 5, 5, endpoint=False)
y = np.linspace(0, 5, 5, endpoint=True)
print(x.size - y.size)
22 Nov, 09:00
import numpy as np
x, dx = np.linspace(0, 8, 9, retstep=True)
print(dx)
21 Nov, 09:00
import numpy as np
a = np.arange(1, 2, 1)
b = np.linspace(1, 2, 1, dtype=int)
print(a + b)
20 Nov, 09:00
import numpy as np
a = np.array((100, 101, 102, 103))
b = np.zeros_like(a)
print(np.sum(b))
19 Nov, 09:00
import numpy as np
a = np.array((100, 101, 102, 103))
b = np.ones_like(a)
print(np.sum(b))
15 Nov, 09:00
import numpy as np
b = np.array([[1., 2.], [3., 4.]])
b[0, 0] = 0
b[1, 1] = 0
a = np.sum(b)
print(a)
14 Nov, 09:00
it = (lambda: i for i in [1, 2])
vals = [f() for f in [*it]]
print(sum(vals))
13 Nov, 09:00
it = (lambda: i for i in [1, 2])
vals = [f() for f in it]
print(sum(vals))
12 Nov, 09:00
a, *b = (1, 2, 3)
x = hasattr(a, '__iter__')
y = hasattr(b, '__iter__')
print(x, y)
11 Nov, 09:00
import struct
s = struct.pack('fhb', 1, 1, 1)
print(len(s))
07 Nov, 09:00
import pickle
s = pickle.dumps({"x": 1})
a = pickle.loads(s[1:])["x"]
print(a)
06 Nov, 09:00
def dec(f):
# Ваш код...
def wrapper(*args, **kwargs):
return f(*args, **kwargs)
return wrapper
@dec
def add(a, b):
return a + b
print(add.__name__)
01 Nov, 09:00
from decimal import Decimal, ROUND_UP, ROUND_DOWN
a = Decimal(1)
b = Decimal(7)
c = a / b
x1 = c.quantize(Decimal('0.1'), rounding=ROUND_DOWN)
x2 = c.quantize(Decimal('0.1'), rounding=ROUND_UP)
print(x2 - x1)
31 Oct, 09:00
class A:
def __call__(self):
return self
a = A()
print(a is a(), a() == a()())
29 Oct, 09:00
def f(f): f(f)
res = f(f)
print(res)
25 Oct, 09:00
def f(x):
return x**3 + 6*x**2 + 12*x + 75
l = [f(i) for i in range(1, 2021, 3)]
s1 = sum([x // 2 for x in l])
s2 = sum([x >> 1 for x in l])
print(s1 - s2)
24 Oct, 09:00
class Number(int, float): pass
x1 = Number(1)
x2 = Number(1.0)
print(x1 == x2)
23 Oct, 09:00
s = set(dir('a')) - set(dir(b'a'))
x = 'encode' in s
y = 'decode' in s
print(x, y)
22 Oct, 09:00
from functools import reduce
vals = (chr(x) for x in range(ord('a'), ord('d')))
print(reduce(lambda acc, x: x + acc[::-1] + x, vals, ''))
17 Oct, 09:00
class MyBool(bool): pass
b = MyBool(True)
print(b == True, b is True)
16 Oct, 09:00
try:
raise IOError()
except OSError as err:
print(isinstance(err, OSError), isinstance(err, IOError))
14 Oct, 09:00
def a(z):
x = 0
try:
x += 1
100/z
x += 1
except ZeroDivisionError:
try:
x += 1
finally:
x += 1
return x
finally:
x += 1
return -1
print(a(0))
11 Oct, 09:00
S = 'hello'
C = bytearray(S, encoding="ascii")
10 Oct, 09:00
from collections import namedtuple
rec = namedtuple('rec', ['x', 'y', 'z'])
comp = rec(1, 2, [4, 5])
09 Oct, 09:00
s = bytearray("hello", encoding="ascii")
08 Oct, 09:00
import numpy as np
m = np.arange(4).reshape(2, 2)
d = np.fliplr(m).diagonal()
print(sum(d), np.trace(m))
04 Oct, 09:00
a = [1]
a.insert(0, a)
a[0][0][-2][-2].append([2])
a[0][0][-1].append(3)
a[0][0][0][0][-1][0] *= -1
s = a[0][1] + a[0][0][2][-1] + a[0][0][2][-2]
print(s)