Tutorial 5: Changing Dtype of Timeseries Data#

Open In Colab Github

The dtype of the all participant’s NumPy arrays in the subject timeseries dictionary can be changed to assist with memory usage.

[1]:
# Download packages
try:
    import neurocaps
except:
    !pip install neurocaps[windows,demo]
[2]:
import numpy as np

from neurocaps.analysis import change_dtype
from neurocaps.utils import simulate_subject_timeseries

subject_timeseries = simulate_subject_timeseries(n_subs=1, n_runs=2, shape=(50, 100))

converted_subject_timeseries = change_dtype(
    subject_timeseries_list=[subject_timeseries], dtype=np.float32
)

for subj_id in subject_timeseries:
    for run in subject_timeseries[subj_id]:
        print(
            f"subj-{subj_id}; {run}:\n"
            f"dtype before conversion {subject_timeseries[subj_id][run].dtype}\n"
            f"dtype after conversion: {converted_subject_timeseries['dict_0'][subj_id][run].dtype}\n"
        )
subj-0; run-0:
dtype before conversion float64
dtype after conversion: float32

subj-0; run-1:
dtype before conversion float64
dtype after conversion: float32