Skip to content
Justice Tech School

zeros, ones, full and empty

Create filled arrays of a given shape.

Example
print(np.zeros(3))
print(np.ones((2, 2), dtype=int))
print(np.full((2, 3), 7))
print(np.eye(3, dtype=int))

Result

[0. 0. 0.]
[[1 1]
 [1 1]]
[[7 7 7]
 [7 7 7]]
[[1 0 0]
 [0 1 0]
 [0 0 1]]

Exercise

All zeros.

np.(5)

Quiz Test

What does eye make?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.