Skip to content

Instantly share code, notes, and snippets.

View f0nzie's full-sized avatar

Alfonso R. Reyes f0nzie

  • Oil Gains Analytics
  • Houston, Texas
View GitHub Profile
@f0nzie
f0nzie / softmax.py
Created September 7, 2017 00:24
softmax
def softmax(x):
"""Calculates the softmax for each row of the input x.
Your code should work for a row vector and also for matrices of shape (n, m).
Argument:
x -- A numpy matrix of shape (n,m)
Returns:
s -- A numpy matrix equal to the softmax of x, of shape (n,m)
@f0nzie
f0nzie / normalize_rows.py
Created September 7, 2017 00:30
Normalize rows of a matrix by dividing rows by the normal of the matrix
def normalizeRows(x):
"""
Implement a function that normalizes each row of the matrix x (to have unit length).
Argument:
x -- A numpy matrix of shape (n, m)
Returns:
x -- The normalized (by row) numpy matrix. You are allowed to modify x.
"""
@f0nzie
f0nzie / image_to_colvector.py
Created September 7, 2017 00:32
Convert a 3D array to a column vector
def image2vector(image):
"""
Argument:
image -- a numpy array of shape (length, height, depth)
Returns:
v -- a vector of shape (length*height*depth, 1)
"""
v = image.reshape((image.shape[0] * image.shape[1] * image.shape[2], 1))
@f0nzie
f0nzie / sigmoid_derivative.py
Last active March 10, 2023 23:15
Compute the gradient (also called the slope or derivative) of the sigmoid function with respect to its input x. You can store the output of the sigmoid function into variables and then use it to calculate the gradient.
def sigmoid_derivative(x):
"""
Compute the gradient (also called the slope or derivative) of the sigmoid function with respect to its input x.
You can store the output of the sigmoid function into variables and then use it to calculate the gradient.
Arguments:
x -- A scalar or numpy array
Return:
ds -- Your computed gradient.
@f0nzie
f0nzie / sigmoid.py
Created September 7, 2017 00:35
Compute the sigmoid of x
def sigmoid(x):
"""
Compute the sigmoid of x
Arguments:
x -- A scalar or numpy array of any size
Return:
s -- sigmoid(x)
"""
@f0nzie
f0nzie / README.md
Created October 15, 2017 21:33 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@f0nzie
f0nzie / table-make-from_text_using_readr.md
Created February 3, 2019 03:55
Make a table from text
title output
R Notebook
html_notebook
@f0nzie
f0nzie / table-make-from_text_using_data_table.md
Created February 3, 2019 04:19
Make a table from text using data.table
title output
R Notebook
html_notebook
library(data.table)
fread("A,B
1,2
@f0nzie
f0nzie / table-make-from_text-data_table-tsv.md
Created February 3, 2019 04:33
Make a table from text (tsv) using data.table
title output
R Notebook
html_notebook
write.table(read.table(text = "
 CHR_A     BP_A          SNP_A  CHR_B         BP_B          SNP_B           R2 
 1    154834183      rs1218582      1    154794318      rs9970364    0.0929391 
@f0nzie
f0nzie / rTorch_linear_regression.Rmd
Created June 11, 2019 04:39
PyTorch - Linear Regression in R - rsuite version
# One chunk - Linear Regression in R
Source: https://medium.com/dsnet/linear-regression-with-pytorch-3dde91d60b50
```{r}
# Force using local Python environment
if (.Platform$OS.type == "unix") {
reticulate::use_python(python = file.path(script_path, "..", "conda", "bin",
"python3"), require = TRUE)
} else if (.Platform$OS.type == "windows") {