numpy - How to get values of functions in an array for a range of values of variables? -
from sympy.abc import * import sympy s import numpy n z = n.array([1,2,3,4,5,6,7,8,9,10]) g = n.array([11,12,13,14,15,16,17,18,19,20]) x = n.array([z+g,z-g,z*g]) i want x range of values of z , g. z , g arrays. if both contain 10 elements, should 100 results?
in code use zand gare symbols, not arrarys. define them arrays:
z = n.linspace(0,1,10) #create arrays g = n.linspace(0,1,10) g = g.reshape(-1,1) # reshape g, such numpy broadcasts them x=n.array([z+g,z-g,z*g]) numpy knows many different ways multiply/add/... entries of several array entries of another. e.g. dot,outer etc.
two other remarks: use import numpy np, "everybody code more easy read others not use from import *, might mask builtin variables.
Comments
Post a Comment