Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

TypeError: slice indices must be integers or None or have an index method #339

Description

@kimm51

Hello,

I'm encountering an error message: "TypeError: slice indices must be integers or None or have an index method" while implementing CS for a brain dataset using the equispaced mask. This error occurs at a specific section of the code, indicating an issue that I'm having trouble understanding.

In the subsample.py file within the equispaced function, I made the following modification:

if offset is None:
    offset = self.rng.randint(0, high=round(acceleration))

mask = np.zeros(num_cols, dtype=np.float32)
mask[offset::acceleration] = 1

return mask

I added the following code snippet:

else:
    offset_value = offset[0] if isinstance(offset, tuple) else offset
    offset = int(offset_value) if offset is not None else None

This modification resolved the issue for a single volume, but when applied to multiple volumes, it did not work as expected.

Additionally, in the transform.py file, I couldn't get the mask function. Here's the relevant code snippet from the apply_mask function:

mask, num_low_frequencies = mask_func(shape, offset, seed)

if padding is not None:
    mask[..., : padding[0], :] = 0
    mask[..., padding[1] :, :] = 0  # padding value inclusive on the right of zeros

masked_data = data * mask + 0.0  # the + 0.0 removes the sign of the zeros

return masked_data, mask, num_low_frequencies

I have attached a screenshot of the error message for reference.

image

Best regards,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions