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 functools | |
import numpy as np | |
for k in range(2, 21): | |
digits = range(1, k) | |
i = abs(functools.reduce(np.lcm, digits)) | |
print(f"The least common multiple of {digits} is {i}") | |
# Output: |
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 transition_matrix(states): | |
"""Create Markov transition matrix from 1D array of states. | |
Parameters | |
---------- | |
states : array_like | |
One-dimensional array of state. The dtype of ``x`` | |
must be integer (e.g. [0, 2, 2, 1, 1, 1, ...]) |
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 multiprocessing | |
from joblib import Parallel, delayed | |
from scipy.spatial.distance import pdist, squareform | |
def _dcorr(y, n2, A, dcov2_xx): | |
"""Helper function for distance correlation bootstrapping. | |
""" | |
# Pairwise Euclidean distances | |
b = squareform(pdist(y, metric='euclidean')) |
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
''' | |
Non-parametric computation of entropy and mutual-information | |
Adapted by G Varoquaux for code created by R Brette, itself | |
from several papers (see in the code). | |
These computations rely on nearest-neighbor statistics | |
''' | |
import numpy as np |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 spindles_detect(x, sf, perc_threshold=90, wlt_params={'n_cycles': 7, 'central_freq': 'auto'}): | |
"""Simple spindles detector based on Morlet wavelet. | |
Parameters | |
---------- | |
x : 1D-array | |
EEG signal | |
sf : float |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# List unique values in a DataFrame column | |
# h/t @makmanalp for the updated syntax! | |
df['Column Name'].unique() | |
# Convert Series datatype to numeric (will error if column has non-numeric values) | |
# h/t @makmanalp | |
pd.to_numeric(df['Column Name']) | |
# Convert Series datatype to numeric, changing non-numeric values to NaN | |
# h/t @makmanalp for the updated syntax! |
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
""" | |
Password brute-force algorithm. | |
List of most probable passwords and english names can be found, respectively, at: | |
- https://github.com/danielmiessler/SecLists/blob/master/Passwords/probable-v2-top12000.txt | |
- https://github.com/dominictarr/random-name/blob/master/middle-names.txt | |
Author: Raphael Vallat | |
Date: May 2018 | |
Python 3 |
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
# Thanks to http://www.jarrodmillman.com/rcsds/lectures/convolution_background.html | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from scipy.stats import gamma | |
def hrf(x): | |
""" Return values for HRF at given times """ | |
# Gamma pdf for the peak | |
peak_values = gamma.pdf(x, 6) | |
# Gamma pdf for the undershoot |
NewerOlder