Generate arrays instantly with zeros(), ones(), full(), eye(), identity(), and diag().
NumPy provides specialized C-level factory functions to allocate and initialize arrays with predetermined structures like identity matrices, diagonal vectors, or uniform values.
Instead of manually building nested loops to fill a matrix, NumPy's creation functions stamp out structured memory buffers in a single CPU instruction.
`zeros(shape)` allocates memory initialized to 0. `ones(shape)` fills with 1. `full(shape, val)` fills with a custom scalar.
z = np.zeros((2, 3)); o = np.ones((2, 3)); f = np.full((2, 3), 7)z = np.zeros(2, 3)z = np.zeros((2, 3))Multi-dimensional shapes must be passed as a tuple `(2, 3)` inside zeros/ones/full.
Solve the objective below using NumPy vectorized syntax
Create a 3x3 identity matrix using `np.eye(3)` and print it.
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]