error in 10_Utilities #26

Closed
opened 2025-11-02 00:01:45 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @kumar-mahendra on GitHub (Sep 1, 2021).

class Dataset 's method collate_fn needs a little change as otherwise following error in thrown when creating dataloader

ValueError: setting an array element with a sequence

Given Code

"""Processing on a batch."""
    # Get inputs
    batch = np.array(batch, dtype=object)
    X = batch[:, 0]    # This line execution throws above error 
    y = np.stack(batch[:, 1], axis=0)

Suggested solution

"""Processing on a batch."""
    # Get inputs
    batch = np.array(batch, dtype=object)
    X = np.stack(batch[:, 0] ,axis=0) 
    y = np.stack(batch[:, 1], axis=0)
```

Originally created by @kumar-mahendra on GitHub (Sep 1, 2021). class `Dataset` 's method `collate_fn` needs a little change as otherwise following error in thrown when creating dataloader `ValueError: setting an array element with a sequence` Given Code ``` """Processing on a batch.""" # Get inputs batch = np.array(batch, dtype=object) X = batch[:, 0] # This line execution throws above error y = np.stack(batch[:, 1], axis=0) ``` Suggested solution ```` """Processing on a batch.""" # Get inputs batch = np.array(batch, dtype=object) X = np.stack(batch[:, 0] ,axis=0) y = np.stack(batch[:, 1], axis=0) ```
Author
Owner

@GokuMohandas commented on GitHub (Sep 1, 2021):

Nice catch Kumar! Since our inputs are of the same length I have to stack them here. In subsequent lessons with variable sequence lengths within a batch, we have to use batch[:, i]. I'll push this fix later today.

@GokuMohandas commented on GitHub (Sep 1, 2021): Nice catch Kumar! Since our inputs are of the same length I have to stack them here. In subsequent lessons with variable sequence lengths within a batch, we have to use batch[:, i]. I'll push this fix later today.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/Made-With-ML#26