Skip to content

Instantly share code, notes, and snippets.

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
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
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
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)
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')
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))
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
(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)]))
@itdxer
itdxer / fuzzy-c-means.py
Last active August 11, 2017 04:40
Fuzzy C-means in Theano
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
@itdxer
itdxer / zca.py
Created November 21, 2016 21:18
import numpy as np
def as_array2d(array):
"""
Transform any array to 2D.
Parameters
----------
array : array-like