Skip to content

Commit

Permalink
add numpy mean and median vector functionsexamples
Browse files Browse the repository at this point in the history
  • Loading branch information
Pullusb committed Jul 3, 2024
1 parent 0542500 commit 6385829
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions snippets/math/mean_vector_from_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from numpy import as np

def mean_vector(vec_list):
'''Get mean vector from a list of vectors
e.g: mean_vector([ob.matrix_world @ co for co in ob_coordinates])
'''
return Vector(np.mean(vec_list, axis=0))

## Without numpy
# n = Vector()
# for v in vec_list:
# n += v
# return n / len(vec_list)
7 changes: 7 additions & 0 deletions snippets/math/median_vector_from_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from numpy import as np

def median_vector(vec_list):
'''Get median vector from a list of vectors
e.g: median_vector([ob.matrix_world @ co for co in ob_coordinates])
'''
return Vector(np.median(vec_list, axis=0))

0 comments on commit 6385829

Please sign in to comment.