Skip to content
Advertisement

Get multiplication table generalized for n dimensions with numpy

Let a = np.arange(1, 4).

To get the 2 dimensional multiplication table for a, I do:

JavaScript

For 3 dimensions, I can do the following:

JavaScript

How could I write a function that takes a numpy array a and a number of dimensions n as input and ouputs the n dimensional multiplication table for a?

Advertisement

Answer

This should do what you need:

JavaScript

Just change n to be whatever dimension you need

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement