Q:

Write a NumPy program to create a function cube which cubes all the elements of an array

0

Write a NumPy program to create a function cube which cubes all the elements of an array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
def cube(e):
    it = np.nditer([e, None])
    for a, b in it:
        b[...] = a*a*a
    return it.operands[1]
print(cube([1,2,3]))

Sample Output:

[ 1  8 27]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now