Block 12: Array Creation Helpers & Shapes
Use factory functions to create arrays of any shape quickly.
Concepts
- np.arange(start, stop, step)
- np.linspace(start, stop, num)
- np.zeros(), np.ones(), np.full(), np.eye()
- reshape(), transpose (.T), flatten()
Code Examples
See exercise below.
Exercise
Create a 3×4 matrix of zeros, print shape, then reshape to 2×6. Create an array of 10 evenly spaced values between 0 and 1 using linspace.
Homework
Write a 'multiplication table' as a 10×10 NumPy array using np.arange and reshape. Tuesday