Error running veloVI when trying to add veloVI outputs to adata

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

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

---------------------------------------------------------------------------
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

The error was due to the following line when trying to scale the latent_time.values

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

running this line yields

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.

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