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 convert_label_to_indexer(index, label): | |
"""Given a pandas.Index and labels (e.g., from __getitem__) for one dimension, | |
return an indexer suitable for indexing an ndarray along that dimension | |
""" | |
if isinstance(label, slice): | |
indexer = index.slice_indexer(label.start, label.stop, label.step) | |
elif np.isscalar(label): | |
indexer = indexer.get_loc(label) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 23 columns, instead of 19 in line 5.
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
"City" "City_Alternate" "Country" "Latitude" "Longitude" "Country_ISO3" "pop1950" "pop1955" "pop1960" "pop1965" "pop1970" "pop1975" "pop1980" "pop1985" "pop1990" "pop1995" "pop2000" "pop2005" "pop2010" "pop2015" "pop2020" "pop2025" "pop2050" | |
"Sofia" "" "Bulgaria" 42.70 23.33 "BGR" 520.00 620.00 710.00 810.00 890.00 980.00 1070.00 1180.00 1190.00 1170.00 1130.00 1170.00 1180.00 1210.00 1230.00 1240.00 1236 | |
"Mandalay" "" "Myanmar" 21.97 96.08 "MMR" 170.00 200.00 250.00 310.00 370.00 440.00 500.00 560.00 640.00 720.00 810.00 920.00 960.00 1030.00 1170.00 1310.00 1446 | |
"Nay Pyi Taw" "Myanmar" 19.75 96.10 "MMR" 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 60.00 930.00 1020.00 1180.00 1320.00 1461 | |
"Yangon" "Rangoon" "Myanmar" 16.87 96.12 "MMR" 1300.00 1440.00 1590.00 1760.00 1950.00 2150.00 2380.00 2630.00 2910.00 3210.00 3550.00 3930.00 4090.00 4350.00 4840.00 5360.00 5869 | |
"Minsk" "" "Belarus" 53.89 27.57 "BLR" 280.00 410.00 550.00 720.00 930.00 1120.00 1320.00 1470.00 1610.00 1650.00 1700.00 1780.00 180 |
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
"""Proof of concept for implementing bottleneck style aggregators with numba | |
These functions aggregate over any number of axes, just like the built-in | |
numpy functions, e.g., | |
- nansum(x) # aggregates over all axes | |
- nansum(x, axis=1) # aggregates over axis 1 | |
- nansum(x, axis=(0, 2)) # aggregtes over axes 0 and 2 | |
""" | |
import functools |
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
def transform_state_vector(rho, U): | |
N = len(U) | |
if rho.shape[-1] == N: | |
# rho is in Hilbert space | |
pass | |
elif rho.shape[-1] == N ** 2: | |
# rho is in Liouville space | |
U = np.kron(U, U) | |
else: | |
raise ValueError('basis transformation incompatible with ' |
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 numpy.lib.stride_tricks import as_strided | |
def broadcast_to(array, shape): | |
"""Expand a numpy.ndarray to a new shape according to broadcasting rules | |
""" | |
array = np.asarray(array) | |
# will raise ValueError if shapes incompatible | |
np.nditer((array,), itershape=shape) |
OlderNewer