Skip to content

Instantly share code, notes, and snippets.

@mocquin
mocquin / element_wise_timeit.py
Last active January 25, 2019 22:28
Element-wise data structure computation time
# Please note the results for larger list can be different
import numpy as np
# making a list, a dict, and an array
list_a = list(np.asarray(np.linspace(0,9,10)).astype(int)) # working with int
array_a = np.array(list_a)
dict_a = {x: x for x in list_a}
from operator import add as opadd
%timeit -r5 list_c = list(map(opadd, list_a, list_a))
@mocquin
mocquin / getattr_ex.py
Created February 7, 2019 10:39
Example of __getattr__ magic method
"""See https://stackoverflow.com/questions/3278077/difference-between-getattr-v
s-getattribute :
__getattr__ is only invoked if the attribute wasn't found the usual ways.
It's good for implementing a fallback for missing attributes, and is probab
ly the one of two you want.
"""
import numpy as np
class foo():
Title: Pelican setup gist
Description: What are the steps to get blog like this one up and running?
You can find this as a gist [here](https://gist.github.com/mocquin/6b79794f2edb87fc671f28f0d2aeb6c1)
For this, you'll need basic knowledge of pip, terminal, virtualenv, python, git, and github.
Disclaimer : this is not a tutorial, this a quick recipe that worked for me. I voluntarly skip most of the explication part.
```
@mocquin
mocquin / seaborn_get_datasets_names.md
Last active December 16, 2020 19:32
Seaborn datasets names
>>> import seaborn as sns
>>> sns.get_datasets_names()
['anagrams',
 'anscombe',
 'attention',
 'brain_networks',
 'car_crashes',
 'diamonds',
 'dots',
@mocquin
mocquin / seaborn_load_dataset.md
Last active December 16, 2020 19:34
Seaborn load dataset
>>> iris_df = sns.load_dataset("iris")
>>> iris_df.head()
 sepal_length 	sepal_width 	petal_length 	petal_width 	species
0 	5.1 	3.5 	1.4 	0.2 	setosa
1 	4.9 	3.0 	1.4 	0.2 	setosa
2 	4.7 	3.2 	1.3 	0.2 	setosa
3 	4.6 	3.1 	1.5 	0.2 	setosa
4 	5.0 	3.6 	1.4 	0.2 	setosa
@mocquin
mocquin / seaborn_load_dataset_from_data_home.md
Created December 16, 2020 19:35
Seaborn load dataset from data_home
>>> sns.load_dataset(
    "iris", 
    data_home="/Users/mocquin/documents/datasets"
)
@mocquin
mocquin / seaborn_get_data_home.md
Created December 16, 2020 19:35
Seaborn get data_home path
>>> sns.get_data_home()
'/Users/mocquin/seaborn-data'
@mocquin
mocquin / seaborn_load_dataset_signature.md
Created December 16, 2020 19:48
Seaborn load_data_set signature
sns.load_dataset(name, cache=True, data_home=None, **kws)
import numpy as np
class Physical():
def __init__(self, value, unit=""):
self.value = value # store the numerical value as a plain numpy array
self.unit = unit
def __repr__(self):
return f"<Physical:({self.value}, {self.unit})"
import numpy as np
class Physical():
def __init__(self, value, unit=""):
self.value = value
self.unit = unit
def __repr__(self):
return f"<Physical:({self.value}, {self.unit})"