2

In wolfram Mathematica, I use Table[] function all the time.

Example of Table function

enter image description here

i1^2 + i3^3 could be any function of parameters (i1,i3).

and

{i1, 1, 9, 2},
5,
{i3, 7, 3, -.5}

is the space of parameters.

For more details see the documentation: https://reference.wolfram.com/language/ref/Table.html

I can do this with a series of for loops in python like this:

import numpy as np



def f(i1,i3):
    return(i1**2+i3**3)
    
arr=np.array([[[
        
        f(i1,i3)
        
        for i3 in np.arange(7,2.5,-.5)]
        for i2 in np.arange(5)]
        for i1 in np.arange(1,11,2)]
        )
print(arr)

Is there a shorter, more compact way of doing it?

4

0 回答 0