Skip to main content
added link to new question with code example
Source Link
natter1
  • 288
  • 1
  • 10

Further disscussion and code example can be found in another question.

Errors

Errors

Further disscussion and code example can be found in another question.

Errors

added Explanation of Errors in Question code
Source Link
natter1
  • 288
  • 1
  • 10

UpdatePrecalculation You

You could go a step further, by precalculating all posible paths for several steps.

Outlook - binomial distribution and minimal distance matrix

After understanding what your code is intended to do, I think your for-loop over all paricles is not doing what you intendbroken.

Also, you only start particles anat the upper and left border?

The name arr is an example for a bad name, because it hints to "array" (thus it was hard to spot the mistake above). Better would be samething like area. Or use h and w (personally I would prefer to name thus as height and width; thats easier to read in most cases)

Update You could go a step further, by precalculating all posible paths for several steps.

Outlook

After understanding what your code is intended to do, I think your for-loop over all paricles is not doing what you intend.

Also, you only start particles an the upper and left border?

The name arr is an example for a bad name, because it hints to "array" (thus it was hard to spot the mistake above). Better would be samething like area.

Precalculation

You could go a step further, by precalculating all posible paths for several steps.

Outlook - binomial distribution and minimal distance matrix

After understanding what your code is intended to do, I think your for-loop over all paricles is broken.

Also, you only start particles at the upper and left border?

The name arr is an example for a bad name, because it hints to "array" (thus it was hard to spot the mistake above). Better would be samething like area. Or use h and w (personally I would prefer to name thus as height and width; thats easier to read in most cases)

added Explanation of Errors in Question code
Source Link
natter1
  • 288
  • 1
  • 10

Errors

After understanding what your code is intended to do, I think your for-loop over all paricles is not doing what you intend.

First:

pos = np.random.randint(0, len(arr))  # will set pos to 0 or 1
# should be:
pos = np.random.randint(0, arr[0])
# or better
random_pos_x = np.random.randint(0, arr[0])
random_pos_y = np.random.randint(0, arr[1])

Also, you only start particles an the upper and left border?

walk(pos,-1,canvas)  # why -1?
...
walk(-1,pos,canvas)  # why -1?

# should be:
walk(random_pos_x ,arr[1]-1, canvas)
walk(arr[0]-1, random_pos_y, canvas)

The name arr is an example for a bad name, because it hints to "array" (thus it was hard to spot the mistake above). Better would be samething like area.

Errors

After understanding what your code is intended to do, I think your for-loop over all paricles is not doing what you intend.

First:

pos = np.random.randint(0, len(arr))  # will set pos to 0 or 1
# should be:
pos = np.random.randint(0, arr[0])
# or better
random_pos_x = np.random.randint(0, arr[0])
random_pos_y = np.random.randint(0, arr[1])

Also, you only start particles an the upper and left border?

walk(pos,-1,canvas)  # why -1?
...
walk(-1,pos,canvas)  # why -1?

# should be:
walk(random_pos_x ,arr[1]-1, canvas)
walk(arr[0]-1, random_pos_y, canvas)

The name arr is an example for a bad name, because it hints to "array" (thus it was hard to spot the mistake above). Better would be samething like area.

added 88 characters in body
Source Link
natter1
  • 288
  • 1
  • 10
Loading
added 917 characters in body
Source Link
natter1
  • 288
  • 1
  • 10
Loading
added 1232 characters in body
Source Link
natter1
  • 288
  • 1
  • 10
Loading
Update with precalculated matrix
Source Link
natter1
  • 288
  • 1
  • 10
Loading
Source Link
natter1
  • 288
  • 1
  • 10
Loading