Skip to content

Instantly share code, notes, and snippets.

View RyotaBannai's full-sized avatar
🛴
Man's soil is still rich enough to direct his own life.

Ryota Bannai RyotaBannai

🛴
Man's soil is still rich enough to direct his own life.
View GitHub Profile
import numpy as np
from numpy.linalg import inv
import statsmodels.api as sm
# from scratch
x = sm.add_constant(x) # add constant in the 0 index
b = inv(x.T.dot(x)).dot(x.T).dot(y)
yest_ols = np.array([b[2]*v**2 + b[1]*v + b[0] for v in x.T[0]])
# with using numpy.linalg.lstsq
{ //json_build_object
"model": "myapp.person",
"pk": 1,
"fields": { //json_build_object
"first_name": "John",
"last_name": "Lennon"
}
}
db=# \t
db=# \a
db=# \o file.json
db=# select row_to_json(t) from meryota_question as t;
//'meryota_question' is just my database name.
[
{
"model": "myapp.person",
"pk": 1,
"fields": {
"first_name": "John",
"last_name": "Lennon"
}
},
{
db=# \t //1st command
db=# \a //2nd command
db=# \o file.json //3rd command
db=# SELECT json_agg(json_build_object( //4thcommand
'pk', t.id,'model','meryota.question', 'fields',
json_build_object('question_text',t.question_text,
'pub_date',t.pub_date))) from meryota_question as t;
$pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
$heroku pg:backups:capture
//Make the latest backup file on Poshgres on heroku
$heroku pg:backups:download
//Download the latest backup file to the localhost(the name is latest.dump)
//Reference is below
N=5
fig, ax = plt.subplots(1, N, figsize=(5, 2.5),
subplot_kw={'xticks':[], 'yticks':[]},
gridspec_kw=dict(hspace=0.1, wspace=0.1))
for i in range(1, N+1):
ax[i-1].imshow(Vt[i].reshape(62, 47), cmap='binary_r')
fig, ax = plt.subplots(2, 5, figsize=(5, 2.5),
subplot_kw={'xticks':[], 'yticks':[]},
gridspec_kw=dict(hspace=0.1, wspace=0.1))
for i in range(5, 10):
ax[0, i-5].imshow(faces.data[i].reshape(62,47), cmap='binary_r')
ax[1, i-5].imshow(X[i].reshape(62,47), cmap='binary_r')
X = US.dot(Vt[:dim,:])
X = X + average_face