1.14.1
Thinking Machines
SciPy (pronounced “Sigh Pie”) is an open-source software for mathematics, science, and engineering.
pipSTOP
Instructor’s note: Do not click this link while streaming.
yt-dlp to download from YouTube.ffmpeg to translate .mp4 files to .wavyt-dlp as follows, from the shell:ffmpeg for Windows and MacOS.yt-dlp and ffmpeg are command line utilites (like Python, Neovim, or ls).ffmpeg directly, it is just used by yt-dlp.yt-dlp to go to the url, download to video, convert it to a .wav, and save it as “psy.wav”curl the file.
curl shell command downloads files from urls.
scipy.ionppdmatplotlib.pyplot is a previous example of a module.scipy.io includes ways to read files.scipy.fft does Fast Fourier Transforms.scipy.stats does statistics.try and except (like if and else) on erroneous code.try and except prevents Python errors.
curl command to get “psy.wav” while (unbeknownst to me) my internet was spotty.0rate amount of time..transpose?np.where to find where the low values occur.
curl these but you probably have to navigate the websites to find the urls regardless.url = "https://..."pd.read_csv(url)os.system("curl " + url + " -o name.csv")import pandas as pd
minwage = pd.read_csv("https://github.com/cd-public/scicom/raw/refs/heads/main/qmd/src/FEDMINNFRWG.csv")
unemploy = pd.read_csv("https://github.com/cd-public/scicom/raw/refs/heads/main/qmd/src/UNRATE.csv")
inflate = pd.read_csv("https://github.com/cd-public/scicom/raw/refs/heads/main/qmd/src/CPIAUCSL.csv")
inflate| observation_date | CPIAUCSL | |
|---|---|---|
| 0 | 1947-01-01 | 21.480 |
| 1 | 1947-02-01 | 21.620 |
| 2 | 1947-03-01 | 22.000 |
| 3 | 1947-04-01 | 22.000 |
| 4 | 1947-05-01 | 21.950 |
| ... | ... | ... |
| 935 | 2024-12-01 | 317.603 |
| 936 | 2025-01-01 | 319.086 |
| 937 | 2025-02-01 | 319.775 |
| 938 | 2025-03-01 | 319.615 |
| 939 | 2025-04-01 | 320.321 |
940 rows × 2 columns
.pct_change()
0 which has no percent change.
column=<name>linregressdf = pd.read_csv("https://gist.githubusercontent.com/GoodmanSciences/c2dd862cd38f21b0ad36b8f96b4bf1ee/raw/1d92663004489a5b6926e944c1b3d9ec5c40900e/Periodic%2520Table%2520of%2520Elements.csv")
df[::30]| AtomicNumber | Element | Symbol | AtomicMass | NumberofNeutrons | NumberofProtons | NumberofElectrons | Period | Group | Phase | ... | FirstIonization | Density | MeltingPoint | BoilingPoint | NumberOfIsotopes | Discoverer | Year | SpecificHeat | NumberofShells | NumberofValence | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Hydrogen | H | 1.007 | 0 | 1 | 1 | 1 | 1.0 | gas | ... | 13.5984 | 0.00009 | 14.175 | 20.28 | 3.0 | Cavendish | 1766.0 | 14.304 | 1 | 1.0 |
| 30 | 31 | Gallium | Ga | 69.723 | 39 | 31 | 31 | 4 | 13.0 | solid | ... | 5.9993 | 5.91000 | 302.910 | 2477.00 | 14.0 | de Boisbaudran | 1875.0 | 0.371 | 4 | 3.0 |
| 60 | 61 | Promethium | Pm | 145.000 | 84 | 61 | 61 | 6 | NaN | artificial | ... | 5.5820 | 7.26000 | 1204.150 | 3273.00 | 14.0 | Marinsky et al. | 1945.0 | NaN | 6 | NaN |
| 90 | 91 | Protactinium | Pa | 231.036 | 140 | 91 | 91 | 7 | NaN | solid | ... | 5.8900 | 15.40000 | 1873.150 | 4300.00 | 14.0 | Hahn and Meitner | 1917.0 | NaN | 7 | NaN |
4 rows × 28 columns
AtomicNumber 43
Element Technetium
Symbol Tc
AtomicMass 98.0
NumberofNeutrons 55
NumberofProtons 43
NumberofElectrons 43
Period 5
Group 7.0
Phase artificial
Radioactive yes
Natural NaN
Metal yes
Nonmetal NaN
Metalloid NaN
Type Transition Metal
AtomicRadius 2.0
Electronegativity 1.9
FirstIonization 7.28
Density 11.5
MeltingPoint 2473.15
BoilingPoint 5150.0
NumberOfIsotopes 23.0
Discoverer Perrier and Segr�
Year 1937.0
SpecificHeat NaN
NumberofShells 5
NumberofValence NaN
Name: 42, dtype: object
from scipy.interpolate import LinearNDInterpolator
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng()
x = rng.random(10) - 0.5
y = rng.random(10) - 0.5
z = np.hypot(x, y)
X = np.linspace(min(x), max(x))
Y = np.linspace(min(y), max(y))
X, Y = np.meshgrid(X, Y) # 2D grid for interpolation
interp = LinearNDInterpolator(list(zip(x, y)), z)
Z = interp(X, Y)
plt.pcolormesh(X, Y, Z, shading='auto')
plt.plot(x, y, "ok", label="input point")
plt.legend()
plt.colorbar()
plt.axis("equal")
plt.show()
df to work with.df to have only these 3 values, then .dropna()X (capitalized) to denote it is a vector or array.Y (capitalized) to denote it is a vector or array.X and YZLinearNDInterpolarNote
AtomicNumber 43
Element Technetium
Symbol Tc
AtomicMass 98.0
NumberofNeutrons 55
NumberofProtons 43
NumberofElectrons 43
Period 5
Group 7.0
Phase artificial
Radioactive yes
Natural NaN
Metal yes
Nonmetal NaN
Metalloid NaN
Type Transition Metal
AtomicRadius 2.0
Electronegativity 1.9
FirstIonization 7.28
Density 11.5
MeltingPoint 2473.15
BoilingPoint 5150.0
NumberOfIsotopes 23.0
Discoverer Perrier and Segr�
Year 1937.0
SpecificHeat NaN
NumberofShells 5
NumberofValence NaN
Name: 42, dtype: object
piecewise.py doesn’t work on arrays unfortunately.(array < value) & (array > value) works.LinearNDInterpolator takes an array of known inputs and an array of known outputs and returns a function that it thinks describes the relationship.df = pd.read_csv("https://gist.githubusercontent.com/GoodmanSciences/c2dd862cd38f21b0ad36b8f96b4bf1ee/raw/1d92663004489a5b6926e944c1b3d9ec5c40900e/Periodic%2520Table%2520of%2520Elements.csv")
df.drop(42)
df = df[["Group", "Period", "Density"]]
df = df.dropna()
f = LinearNDInterpolator(np.column_stack((df["Group"],df["Period"])), df["Density"])
me = df[(abs(df["Group"] - 7) + abs(df["Period"] - 5)) < 2]["Density"].mean()
[f(7,5), me, Tc["Density"]]