Skip to content

ValueError: x and y must have same first dimension, but have shapes (1,) and (10,) #124

@atdortch

Description

@atdortch

I am trying to fix this answer. please help. I think it has something to do with my arrays.

import numpy as np
import random as rand
import matplotlib.pyplot as plt

particles = 10
steps = 20

position = np.zeros(particles) # position of particles start at zero

right = 1; left = 2 # assign values to left and right positions

for step in range(steps):
for p in range(particles):
walk = rand.randint(1,2)
if walk == right:
position[p] += 1
elif walk == left:
position[p] -=1
displacement = position-0

print(position)

plt.plot(steps,displacement)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions