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 typing import Union | |
import pandas as pd | |
from trading_calendars import TradingCalendar, get_calendar | |
class TradingDay: | |
"""Offset for trading days | |
The class is useful to find previous and next trading days from given date. |
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
# -*- coding: utf-8 -*- | |
import multiprocessing as mp | |
import matlab.engine as me | |
def start_matlab(ready_event, close_event): | |
print('Starting matlab...') | |
eng = me.start_matlab(option='-nodesktop') |
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 time | |
import numpy as np | |
from scipy.sparse import csr_matrix | |
def make_matrix(shape, nnz): | |
i = np.random.randint(0, shape[0] - 1, nnz) | |
j = np.random.randint(0, shape[1] - 1, nnz) | |
data = np.random.randn(nnz) |
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 time | |
import numpy as np | |
from scipy.sparse import diags | |
def make_matrix(pcount): | |
x = np.linspace(0., 10., pcount) | |
dx = np.diff(x) | |
odx = 1. / dx |
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 typing import Optional | |
from pydantic import BaseModel, validator | |
class MyModel(BaseModel): | |
name: Optional[str] | |
class Config: | |
validate_assignment = True |
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 index_offset(a): | |
if a.base is None: | |
ravel_index = 0 | |
shape = a.shape | |
else: | |
byte_offset = np.byte_bounds(a)[0] - np.byte_bounds(a.base)[0] | |
ravel_index = byte_offset // a.dtype.itemsize | |
shape = a.base.shape |
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
name='laplace' params=LaplaceAlgoParams(gradient_sigma=1.0, laplacian_sigma=2.0) | |
name='gauss' params=GaussAlgoParams(gaussian_sigma=1.5) | |
1 validation error for AlgoSettings | |
name | |
Cannot find algorithm 'lol'. Existing algorithms: ['laplace', 'gauss'] (type=value_error) | |
1 validation error for AlgoSettings | |
params | |
<class '__main__.GaussAlgoParams'> parameters type is invalid for 'laplace' algorithm. Parameters type must be a subclass of <class '__main__.LaplaceAlgoParams'> (type=type_error) |
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 mpl_toolkits.mplot3d import Axes3D | |
from mpl_toolkits.mplot3d.art3d import Poly3DCollection | |
import matplotlib.pyplot as plt | |
# x y z | |
a = (1, 1, 1) # p1 | |
b = (2, 2, 2) # p2 | |
x, y, z = 0, 1, 2 |
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 itertools | |
def slide(seq, n=2): | |
"""Returns a sliding window (of width n) over data from the sequence | |
s -> (s0, s1, ..., s[n-1]), (s1, s2, ..., sn), ... | |
""" | |
it = iter(seq) | |
result = tuple(itertools.islice(it, n)) | |
if len(result) == n: |
NewerOlder