Broadcasting rules (memorize these):
If shapes di er in number of dims, prepend 1s to the
smaller shape
Dimensions must match or one of them must be 1
Mismatches that aren't 1 → error
df2 = [Link]([Link](100, 4),
columns=['A','B','C','D'])
import [Link] as plt
x = [Link](0, 2*[Link], 1000) # NumPy makes the data
y = [Link](x) + 0.1 * [Link](1000) # add noise
[Link](x, y) # Matplotlib consumes NumPy arrays directly
[Link]()
Matplotlib/Seaborn accepts NumPy arrays natively. You generate data with NumPy,
visualize with Matplotlib.
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
X = [Link](100, 5) # 100 samples, 5 features — NumPy array
y = X @ [Link]([1,2,3,4,5]) + [Link](100) # target
X_train, X_test, y_train, y_test = train_test_split(X, y)
model = LinearRegression().fit(X_train, y_train)
# Predictions ARE NumPy arrays
predictions = [Link](X_test) # returns [Link]
import torch
np_array = [Link]([[1.0, 2.0], [3.0, 4.0]])
tensor = torch.from_numpy(np_array) # zero-copy! shared memory
back = [Link]() # back to NumPy
# In TensorFlow
import tensorflow as tf
tf_tensor = [Link](np_array)
The conversion is often zero-copy — they share the same memory block.
That's why NumPy is the universal interface.