# Modifying \`point\` in-place in custom step method

**URL:** <https://discourse.pymc.io/t/modifying-point-in-place-in-custom-step-method/3282>\
**Category:** Questions\
**Created:** [May 17, 2019, 7:33pm UTC](https://discourse.pymc.io/t/modifying-point-in-place-in-custom-step-method/3282 "2019-05-17T19:33:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hamster\_on\_wheels](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hamster_on_wheels/32/1823_2.png) [@Hamster\_on\_wheels](https://discourse.pymc.io/u/Hamster_on_wheels)\
**Post date:** [May 17, 2019, 7:33pm UTC](https://discourse.pymc.io/t/modifying-point-in-place-in-custom-step-method/3282/1 "2019-05-17T19:33:28Z")

</div>

Old development [guide](https://pymc-devs.github.io/pymc/extending.html?highlight=place) for pymc2 states:

> 8.4 A second warning: Don’t update stochastic variables’ values in-place

Is this still a bad idea for pymc3? Would that mess up the caching of the values of parameters in NUTS?

I try to update the old code [here](https://stats.stackexchange.com/questions/97003/pymc-how-can-i-use-a-custom-sampler-for-one-specific-variable-in-a-model).

Test:

```auto
import pymc3 as pm
import matplotlib.pyplot as plt
import numpy as np
from pymc3.step_methods.arraystep import BlockedStep
from pymc3.model import modelcontext

class StandardNormalStep(BlockedStep):
    def __init__ (self, vars, model=None):
        model = modelcontext(model)
        # Must name atribute as self.vars
        self.vars = vars
        self.m = model

    def step(self, point):
        # [()] is indexing a scalar np.ndarray
        # We are modifying the 0D np.ndarray in-place.
        #print(id(self)) #Does nuts instantiate multiple steps?
        point[self.vars[0].name][()] = np.random.normal(0, 1)
        return point

def main():
    with pm.Model() as model:
        A = pm.Flat('A')
        step_A = StandardNormalStep([A])
        trace = pm.sample(5000, step=[step_A])
        pm.traceplot(trace)
        plt.show()

main()

```

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [May 25, 2019, 6:09am UTC](https://discourse.pymc.io/t/modifying-point-in-place-in-custom-step-method/3282/2 "2019-05-25T06:09:48Z")

</div>

You can certainly modify the value inplace, that’s essentially how the compound step operates. For example, you can do Laplace approximation on some random variable, update the value and pass it on to NUTS

> <https://github.com/junpenglao/Planet_Sakaar_Data_Science/blob/master/Ports/Laplace%2520approximation%2520in%2520pymc3.ipynb>
