Saturday, January 17, 2026
HomeLanguagesEvaluate a 3-D polynomial at points (x, y, z) with 4D array...

Evaluate a 3-D polynomial at points (x, y, z) with 4D array of coefficient using NumPy in Python

In this article, we will look at how to evaluate a 3-dimensional polynomial at points (x, y, z) with a 4D array of coefficients using NumPy in Python.

polynomial.polyval3d method 

We are using polynomial.polyval3d() function present in the NumPy module of python for the evaluation purpose of a 3-dimensional polynomial at points x, y, and z.Here at points x, y, and z, the 3-dimensional series is being evaluated if x, y, and z have a similar shape, if either from x, y, and z is a list or a tuple then before evaluation it is going to be converted to an nd-array else it is kept as it is. Also if it is not an nd-array, it will be treated as a scalar. Another parameter ‘C’ is present which is an ordered array of coefficients with multi-degree terms i, j, k present in C[i, j, k]. 

Syntax : polyval3d(x, y, z, C)

Parameters

  • x, y, z : The three-dimensional series is analyzed at the array-like points.
  • C :  It is an sorted array of coefficients organised so that the coefficient of the term of multi-degree i,j,k is contained in c[i,j,k].

Returns: the multidimensional polynomial values on the points formed with the triples of the corresponding values from x, y and z.

Example 1 :

Python3




# importing numpy module and polyval3d function
import numpy as np
from numpy.polynomial.polynomial import polyval3d
 
# creating an 4d array of coefficients 'C'
# using numpy
C = np.arange(24).reshape(2,2,3,2)
 
# Now using polyval3d function we are
# evaluating the 3D polynomial at points
# (x,y,z)
print(polyval3d([2,1],[1,2],[2,3], C))


Output :

[[ 582. 1032.]
 [ 624. 1110.]]

Example 2 :

Python3




# importing numpy module and polyval3d function
import numpy as np
from numpy.polynomial.polynomial import polyval3d
 
# creating an 4d array of coefficients 'C'
C = np.arange(72).reshape(3,2,6,2)
 
# Now using polyval3d function evaluate
# the 3D polynomial at points (x,y,z)
x = [4,1]
y = [1,2]
z = [2,3]
 
print("The result of evaluation by polyval3d function is : \n",
      polyval3d(x, y, z, C))


Output :

The result of evaluation by polyval3d function is : 
 [[146412. 134370.]
 [149058. 137646.]]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
117 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12062 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS