pythonnumpy
Ben Gorman

Ben Gorman

Life's a garden. Dig it.

Given peanut, a 4x5 array of 0s, and butter, a 5-element 1-d array of indices, fill the rows of peanut with 1s starting from the column indices given by butter.

import numpy as np
 
peanut = np.zeros(shape = (4, 5))
butter = np.array([3, 0, 4, 1])
 
print(peanut)
# [[0. 0. 0. 0. 0.]
#  [0. 0. 0. 0. 0.]
#  [0. 0. 0. 0. 0.]
#  [0. 0. 0. 0. 0.]]
 
print(butter)
# [3 0 4 1]

Solution

This content is gated

Subscribe to one of the products below to gain access