8000 Merge pull request #92 from vladislavneon/fix-91 · lhoupert/from-python-to-numpy@8977533 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8977533

Browse files
authored
Merge pull request rougier#92 from vladislavneon/fix-91
4.4 Spatial vectorization/numpy implementation incorrect operators
2 parents f476c2b + 84a06e5 commit 8977533

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

04-code-vectorization.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ We're ready to write our three rules:
806806
807807
# Normalize the result
808808
norm = np.sqrt((target*target).sum(axis=1)).reshape(n, 1)
809-
target *= np.divide(target, norm, out=target, where=norm != 0)
809+
np.divide(target, norm, out=target, where=norm != 0)
810810
811811
# Alignment at constant speed
812812
target *= max_velocity
@@ -827,7 +827,7 @@ We're ready to write our three rules:
827827
828828
# Normalize the result
829829
norm = np.sqrt((target*target).sum(axis=1)).reshape(n, 1)
830-
target *= np.divide(target, norm, out=target, where=norm != 0)
830+
np.divide(target, norm, out=target, where=norm != 0)
831831
832832
# Cohesion at constant speed (max_velocity)
833833
target *= max_velocity
@@ -843,15 +843,15 @@ We're ready to write our three rules:
843843
repulsion = np.dstack((dx, dy))
844844
845845
# Force is inversely proportional to the distance
846-
repulsion = np.divide(repulsion, distance.reshape(n, n, 1)**2, out=repulsion,
847-
where=distance.reshape(n, n, 1) != 0)
846+
np.divide(repulsion, distance.reshape(n, n, 1)**2, out=repulsion,
847+
where=distance.reshape(n, n, 1) != 0)
848848
849849
# Compute direction away from others
850850
target = (repulsion*mask.reshape(n, n, 1)).sum(axis=1)/count.reshape(n, 1)
851851
852852
# Normalize the result
853853
norm = np.sqrt((target*target).sum(axis=1)).reshape(n, 1)
854-
target *= np.divide(target, norm, out=target, where=norm != 0)
854+
np.divide(target, norm, out=target, where=norm != 0)
855855
856856
# Separation at constant speed (max_velocity)
857857
target *= max_velocity

0 commit comments

Comments
 (0)
0