# Error running veloVI when trying to add veloVI outputs to adata

**URL:** <https://discourse.scverse.org/t/error-running-velovi-when-trying-to-add-velovi-outputs-to-adata/1768>\
**Category:** scVelo\
**Created:** [September 22, 2023, 5:50am UTC](https://discourse.scverse.org/t/error-running-velovi-when-trying-to-add-velovi-outputs-to-adata/1768 "2023-09-22T05:50:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmnzo5gy](https://avatars.discourse-cdn.com/v4/letter/h/9e8a1a/32.png) [@hmnzo5gy](https://discourse.scverse.org/u/hmnzo5gy)\
**Post date:** [September 22, 2023, 5:50am UTC](https://discourse.scverse.org/t/error-running-velovi-when-trying-to-add-velovi-outputs-to-adata/1768/1 "2023-09-22T05:50:34Z")

</div>

When I attempt to add veloVI output to adata using the following

```auto
def add_velovi_outputs_to_adata(adata, vae):
    latent_time = vae.get_latent_time(n_samples=25)
    velocities = vae.get_velocity(n_samples=25, velo_statistic="mean")

    t = latent_time
    scaling = 20 / t.max(0)

    adata.layers["velocity"] = velocities / scaling
    adata.layers["latent_time_velovi"] = latent_time

    adata.var["fit_alpha"] = vae.get_rates()["alpha"] / scaling
    adata.var["fit_beta"] = vae.get_rates()["beta"] / scaling
    adata.var["fit_gamma"] = vae.get_rates()["gamma"] / scaling
    adata.var["fit_t_"] = (
        torch.nn.functional.softplus(vae.module.switch_time_unconstr)
        .detach()
        .cpu()
        .numpy()
    ) * scaling
    adata.layers["fit_t"] = latent_time.values * scaling[np.newaxis, :]
    adata.var['fit_scaling'] = 1.0

add_velovi_outputs_to_adata(adata, vae)

```

I encounter the following ValueError

```auto
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/Users/ab/Downloads/vea_python/vea_python_velo/vea_totalvi_scvelo_new.ipynb Cell 164 line 2
     20 mac_adata.layers["fit_t"] = latent_time.values * scaling[np.newaxis, :]
     21 mac_adata.var['fit_scaling'] = 1.0
---> 23 add_velovi_outputs_to_adata(mac_adata, vae)

/Users/ab/Downloads/vea_python/vea_python_velo/vea_totalvi_scvelo_new.ipynb Cell 164 line 2
     13 mac_adata.var["fit_gamma"] = vae.get_rates()["gamma"] / scaling
     14 mac_adata.var["fit_t_"] = (
     15 torch.nn.functional.softplus(vae.module.switch_time_unconstr)
     16 .detach()
     17 .cpu()
     18 .numpy()
     19 ) * scaling
---> 20 mac_adata.layers["fit_t"] = latent_time.values * scaling[np.newaxis, :]
     21 mac_adata.var['fit_scaling'] = 1.0

File ~/miniconda3/envs/scanpy/lib/python3.11/site-packages/pandas/core/series.py:1033, in Series. __getitem__ (self, key)
   1030 key = np.asarray(key, dtype=bool)
   1031 return self._get_values(key)
-> 1033 return self._get_with(key)

File ~/miniconda3/envs/scanpy/lib/python3.11/site-packages/pandas/core/series.py:1048, in Series._get_with(self, key)
   1043 raise TypeError(
...
    344 "Multi-dimensional indexing (e.g. `obj[:, None]`) is no longer "
    345 "supported. Convert to a numpy array before indexing instead."
    346 )

ValueError: Multi-dimensional indexing (e.g. `obj[:, None]`) is no longer supported. Convert to a numpy array before indexing instead.

```

Any idea how I can resolve this? Thank you

---

<div class="post-metadata">

**Author:** ![hmnzo5gy](https://avatars.discourse-cdn.com/v4/letter/h/9e8a1a/32.png) [@hmnzo5gy](https://discourse.scverse.org/u/hmnzo5gy)\
**Post date:** [September 25, 2023, 6:04am UTC](https://discourse.scverse.org/t/error-running-velovi-when-trying-to-add-velovi-outputs-to-adata/1768/2 "2023-09-25T06:04:12Z")

</div>

The error was due to the following line when trying to scale the latent\_time.values

```auto
adata.layers["fit_t"] = latent_time.values * scaling[np.newaxis, :]

```

running this line yields

```auto
Multi-dimensional indexing (e.g. `obj[:, None]`) is no longer supported. Convert to a numpy array before indexing instead.

```

Running the following code resolved the problem, as mentioned in this [page](https://github.com/YosefLab/velovi/issues/18).

```auto
scaling = scaling.to_numpy()
adata.layers["fit_t"] = latent_time.values * scaling[np.newaxis, :]

```
