Instantly share code, notes, and snippets.

# Yuri itdxer

Last active August 13, 2023 15:08
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import math from functools import reduce from collections import namedtuple def multiply_all(numbers): return reduce(int.__mul__, numbers) # 1. Highly composite number consists only of the consecutive primes # 2. Larger primes cannot have larger powers, since the number can always be reduced without effecting # number of divisors
Created October 4, 2020 17:56
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import numpy as np from itertools import combinations primes = [2, 2, 2, 5, 5, 7] number = 1400 assert np.prod(primes) == number # sanity check observed_sets = set() n_hips = 0
Created October 4, 2020 14:26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import random n_start_milk_choc = 2 n_start_black_choc = 8 n_trials = 1000000 n_milk_last = 0 for _ in range(n_trials): prev_pulled_choc = None
Created May 21, 2020 15:31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import numpy as np n_rolls = 10000000 n_sides = 20 min_dice_value = 8 rolls_1 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1 rolls_2 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1 print('-' * 30)
Created May 21, 2020 15:23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import numpy as np n_rolls = 10000000 n_sides = 20 rolls_1 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1 rolls_2 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1 print('-' * 30) print('advantage of disadvantages')
Created November 22, 2018 15:14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import numpy as np import tensorflow as tf np.random.seed(0) w1 = np.random.random((3, 3, 1, 100)) w2 = np.random.random((3, 3, 1, 100)) x1 = np.random.random((1, 256, 256, 1)) x2 = np.random.random((1, 256, 256, 1))
Created August 15, 2018 11:35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 from collections import namedtuple def flatten_tuples(values): for value in values: if isinstance(value, tuple): for inner_value in flatten_tuples(value): yield inner_value else: yield value
Last active August 14, 2018 05:21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 (defn replace-values [array current-value new-value] (assoc array (.indexOf array current-value) new-value)) (defn swap-balls-in-boxes [box-a box-b] (let [random-ball-a (rand-nth box-a) random-ball-b (rand-nth box-b)] [(replace-values box-a random-ball-a random-ball-b) (replace-values box-b random-ball-b random-ball-a)]))
Last active August 11, 2017 04:40
Fuzzy C-means in Theano
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import theano import theano.tensor as T import numpy as np def asfloat(value): """ Convert variable to float type configured by theano floatX variable. Parameters
Created November 21, 2016 21:18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import numpy as np def as_array2d(array): """ Transform any array to 2D. Parameters ---------- array : array-like