For example if you need a 3x5 matrix with the 1 at index (2, 3), just make a 1D array, then reshape it:
M, N = 3, 5
i, j = 2, 3
np.eye(1, M * N, k=(i+1) * M + j).reshape(M, N)
array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 1., 0., 0.]])
It may help to know that every multi-dimensional numpy array is internally represented as a 1D array, with some wrapper logic to handle strides and indexing. That means this solution here can also generalise to any dimension with the appropriate arithmetic. Here's a generalization:
def make_nd_array_with(dims, index):
return (np.eye(1,
np.prod(dims),
k=(((np.array(index[:-1]) + 1) * dims[:-1]).sum() + index[-1]))
.reshape(*dims))
make_nd_array_with((M,N), (i,j))
array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 1., 0., 0.]])
Note that this addresses your constraint of wanting to do this in a single line, but the generally canonical solution is to create an array of zeros and set a single value, as the comments and other answer mentions.
arr = np.zeros(M, N)
arr[i, j] = 1