```python
import numpy as np
from sympy import *
init_printing(use_latex='mathjax')
```


```python
def get_jacobian(expressions, symbols):
    rows = len(expressions)
    columns = len(symbols)

#     print("Expressions:")
#     for expression in expressions:
#         display(expression)

    results = [[0 for x in range(columns)] for y in range(rows)] 
    for row, expression in enumerate(expressions):
        for column, symbol in enumerate(symbols):
#             print('Row %d, column %d, expression: %s, symbol: %s' % (row, column, expression, symbol))
            df = diff(expression, symbol)
#             print("DF: %s" % df)
            results[row][column] = df
    return results
```


```python
def get_hessians(jacobian, symbols):
    jacobian = np.array(jacobian)
    rows, columns = jacobian.shape
    hessians = [[[None for z in range(len(symbols))] for x in range(columns)] for y in range(rows)] 
    for row in range(rows):
        for column in range(columns):
            for index, symbol in enumerate(symbols):
                df = diff(jacobian[row, column], symbol)
                hessians[row][column][index] = df
            
    return hessians
```


```python
def evaluate_at(exprs, symbols):
    results = []
    def process_list(exprs, symbols):
        r = []
        for expr in exprs:
            if isinstance(expr, list):
                r.append(process_list(expr, symbols))
            else:
                r.append(expr.subs(symbols))
        return r

    
    if isinstance(exprs, list):
        results = process_list(exprs, symbols)
    else:
        results = []
        results.append(exprs.subs(symbols))
    return results
```


```python
x, y = symbols('x y')
f = sin(pi * x - y * x ** 2 )
j = get_jacobian([f], [x,y])
h = get_hessians(j, [x,y])
evaluate_at(h, {x: 1, y: pi})
```




$$\left [ \left [ \left [ - 2 \pi, \quad -2\right ], \quad \left [ -2, \quad 0\right ]\right ]\right ]$$




```python

```

3de72c805f17cb960a6193653ef3be2efb9a0618
ipynb
Jupyter Notebook
Certification 2/Week4.2 - 2D polynomial estimation - final.ipynb
The-Brains/MathForMachineLearning
5cbd9006f166059efaa2f312b741e64ce584aa1f
MIT
2018-04-16T02:53:59.000Z
2021-05-16T06:51:57.000Z
Certification 2/Week4.2 - 2D polynomial estimation - final.ipynb
The-Brains/MathForMachineLearning
5cbd9006f166059efaa2f312b741e64ce584aa1f
MIT
Certification 2/Week4.2 - 2D polynomial estimation - final.ipynb
The-Brains/MathForMachineLearning
5cbd9006f166059efaa2f312b741e64ce584aa1f
MIT
2019-05-20T02:06:55.000Z
2020-05-18T06:21:41.000Z
Qwen/Qwen-72B
1. YES
2. YES