Info on some python packages.
np.array([(1.5,2,3), (4,5,6)], dtype = float)
arr.shape
np.fromiter(list_gen)
(UNVERIFIED)np.inf
np.identity(n)
(where n
is number of rows)np.add(m1, m2)
or just m1 + m2
dtype
is float
np.empty(<shape>)
np.full(<shape>, val)
np.dot
and matmul
(@
) aren't the same
None
??shape
https://stackoverflow.com/questions/48200911/very-basic-numpy-array-dimension-visualization
np.vstack
: stack two matrices one below the othernp.hstack
: stack two matrices side by side>>> a = np.array([[1,0],[2,0],[3,0]])
>>> a
array([[1, 0],
[2, 0],
[3, 0]])
>>> np.hstack([a,a])
array([[1, 0, 1, 0],
[2, 0, 2, 0],
[3, 0, 3, 0]])
>>> np.zeros(3)
0., 0., 0.])
array([
>>> np.zeros(3).shape
3,)
(
>>> np.zeros(3).reshape(1,3)
0., 0., 0.]])
array([[
>>> np.zeros(3).reshape(1,3).shape
1, 3)
(
###
>>> np.zeros((1,3))
0., 0., 0.]])
array([[
>>> np.zeros((1,3)).shape
1, 3) (
https://numpy.org/doc/stable/reference/generated/numpy.zeros.html
>>> np.array([[0, 1], [0, 0]])
array([[0, 1],
[0, 0]])
>>> np.full((2,2), 3)
3, 3],
array([[3, 3]])
[
>>> np.full((2,2), np.inf)
array([[inf, inf],
[inf, inf]])
>>> np.full((3,2), [1,2])
1, 2],
array([[1, 2],
[1, 2]]) [
https://numpy.org/doc/stable/reference/generated/numpy.full.html
np.dot
np.concatenate([v1, v2])
Remember that determinant is not defined for non-square matrices.
>>> import numpy as np
>>> np.linalg.det(np.array([[1,2],
... [3,4]]))
...
-2.0000000000000004
https://numpy.org/doc/stable/reference/generated/numpy.linalg.det.html
>>> np.linalg.eigvals(np.array([[1,2],
... [3,4]]))
...
array([-0.37228132, 5.37228132])
# Product of Eigen values is determinant
>>> np.prod(np.linalg.eigvals(np.array([[1,2],[3,4]])))
-1.9999999999999998
https://numpy.org/doc/stable/reference/generated/numpy.linalg.eigvals.html
df.stack()
pd.read_csv("~/b.csv", index_col=0)
df.to_csv("~/out.csv")
iloc[0]
df.columns
df.index
level??
axis
Series
to make a DataFrame
>>> pd.concat([s1, s2], axis=1)
>>> pd.concat([s1, s2], axis=1).columns
RangeIndex(start=0, stop=2, step=1)
# Read from a csv file
>>> df = pd.read_csv("name.csv")
# Columns
>>> df.columns
Index(['Site Type', 'Used', 'Fixed', 'Prohibited', 'Available', 'Util%'], dtype='object')
# Number of rows
>>> a.index
RangeIndex(start=0, stop=16, step=1)
https://docs.scipy.org/doc/scipy/reference/sparse.html
>>> import scipy
>>> import numpy as np
>>> X = scipy.sparse.csr_matrix(1./2.*np.array([[0.,1.],[1.,0.]]))
>>> X
<2x2 sparse matrix of type '<class 'numpy.float64'>'
with 2 stored elements in Compressed Sparse Row format>
>>> print(X)
0, 1) 0.5
(1, 0) 0.5 (
nx.adjacency_matrix(G)
nx.attr_matrix(G, <attr-name>)
nx.attr_matrix(G, "weight")
Adding edges implicitly adds nodes.
Edges from/to on a node in undirected graphs: G.edges(<node>)
Edges incident on a node in directed graphs: G.in_edges(<node>)
Edges outgoing from a node in directed graphs: G.out_edges(<node>)
Check if an edge exists: DiGraph.has_edge(n1, n2)
Add edge with weight: G.add_edge(from, to, weight=<weight>)
Node attributes: G[<node>]
or G.nodes[<node>]
Edge attributes: G[n1][n2]['<attr-name>'] = <attr-val>
Get edge data: G.get_edge_data(n1, n2)
https://www.crummy.com/software/BeautifulSoup/bs4/doc/
import pathlib
from bs4 import BeautifulSoup
= pathlib.Path("/home/user/Downloads/input.html")
html_path = html_path.read_text()
htmlstr = BeautifulSoup(htmlstr)
soup = soup.find(id='content-container') content
soup.find_all("tagname", class_="classname")
soup.find(id='content-container')
conda create -n <env-name> [python=3.6.8] [packages needed]
conda activate <env-name>
conda install pip
conda install git
conda env remove -n <env-name>
conda remove <package-name>
Tools:
pytest durations=0 # show tests that ran for more than 0s