Data Science for Electron Microscopy
Lecture 1: Introduction
FAU Erlangen-Nürnberg
Institute of Micro- and Nanostructure Research




Interactive deep learning book with code, math, and discussions
Implemented with PyTorch, NumPy/MXNet, JAX, and TensorFlow
Adopted at 500 universities from 70 countries
We will use the pytorch framework for our coding
















ndarray in MXNetTensor in PyTorch and TensorFlowndarray with additional featuresarange(n) for evenly spaced values (0 to n-1)tensor([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.])
numel() to get total element countshape attribute to get dimensionsreshape to change shape without changing values-1 to automatically infer one dimensionx.reshape(-1, 4) or x.reshape(3, -1)torch.zeros((2, 3, 4))torch.ones((2, 3, 4))torch.randn(3, 4)torch.tensor([[2, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]])start:stop)X[1, 2] = 17: selects all elements along an axis+)-)*)/)**)torch.cat with list of tensorsX = torch.arange(12, dtype=torch.float32).reshape((3,4))
Y = torch.tensor([[2.0, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]])
torch.cat((X, Y), dim=0), torch.cat((X, Y), dim=1)(tensor([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[ 2., 1., 4., 3.],
[ 1., 2., 3., 4.],
[ 4., 3., 2., 1.]]),
tensor([[ 0., 1., 2., 3., 2., 1., 4., 3.],
[ 4., 5., 6., 7., 1., 2., 3., 4.],
[ 8., 9., 10., 11., 4., 3., 2., 1.]]))
X == Y creates tensor of 1s and 0sX.sum() reduces to single elementY = X + Y creates new memoryid() functionY[:] = <expression>zeros_like for initializationX[:] = X + Y or X += Y for efficiencyX.numpy(): Tensor → NumPy arraytorch.from_numpy(A): NumPy array → Tensoritem() or built-in functionsfloat(a), int(a)X < Y and X > Ybackward() methodgrad attributex.grad.zero_()gradient for historical reasonsz = x * y and y = x * xx on zy to create uyuz = x * utensor([True, True, True, True])
y persistsya to vector/matrix
©Philipp Pelz - FAU Erlangen-Nürnberg - Data Science for Electron Microscopy