Skip to content

ValueError: setting an array element with a sequence #5

Description

@331Dala

training = np.array(training)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (29, 2) + inhomogeneous part.

Try these !!! If u encounter an error above.
#reaplace code

training = np.array(training)
train_x = list(training[:, 0])
train_y = list(training[:, 1])

#as below

train_x = np.array([pair[0] for pair in training])
train_y = np.array([pair[1] for pair in training])

I think it raise valueerror due to array element not match.

#For example:

# Invalid (sublists have different lengths)
data = [[1, 2], [3], [4, 5, 6]]
np.array(data) # Will raise the error

# Valid (all sublists have the same length)
data = [[1, 2], [3,4], [5, 6]]
np.array(data)  # OK

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions