10.02.2021 Views

Neural Networks from Scratch in Python by Harrison Kinsley, Daniel Kukie a

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2 - Coding Our First Neurons - Neural Networks from Scratch in Python

a ​= ​[​1​, ​2​, ​3​]

np.array([a])

33

>>>

array([[​1​, ​2​, ​3​]])

Again, note that we encase ​a​ in brackets before converting to an array in this case.

Or we can turn it into a 1D array and expand dimensions using one of the NumPy abilities:

a ​= ​[​1​, ​2​, ​3​]

np.expand_dims(np.array(a), ​axis​=​0​)

>>>

array([[​1​, ​2​, ​3​]])

Where ​np.expand_dims() ​adds a new dimension at the index of the ​axis​.

A column vector is a matrix where the second dimension’s size equals 1, in other words, it’s an

array of shape (n, 1):

With NumPy it can be created the same way as a row vector, but needs to be additionally

transposed ​—​ transposition turns rows into columns and columns into rows:

To turn vector ​b​ into row vector ​b​, we’ll use the same method that we used to turn vector ​a​ into

row vector ​a​, then we can perform a transposition on it to make it a column vector ​b​:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!