Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
47a0088a
Commit
47a0088a
authored
Jul 29, 2017
by
Paul McCarthy
🚵
Browse files
Transform veclength/normalise functions can do multiple vectors at once
parent
156454ec
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/utils/transform.py
View file @
47a0088a
...
...
@@ -55,13 +55,26 @@ def concat(*xforms):
def
veclength
(
vec
):
"""Returns the length of the given vector. """
return
np
.
sqrt
(
np
.
dot
(
vec
,
vec
))
"""Returns the length of the given vector(s).
Multiple vectors may be passed in, with a shape of ``(n, 3)``.
"""
vec
=
np
.
array
(
vec
,
copy
=
False
).
reshape
(
-
1
,
3
)
return
np
.
sqrt
(
np
.
einsum
(
'ij,ij->i'
,
vec
,
vec
))
def
normalise
(
vec
):
"""Normalises the given vector to unit length. """
return
vec
/
veclength
(
vec
)
"""Normalises the given vector(s) to unit length.
Multiple vectors may be passed in, with a shape of ``(n, 3)``.
"""
vec
=
np
.
array
(
vec
,
copy
=
False
).
reshape
(
-
1
,
3
)
n
=
(
vec
.
T
/
veclength
(
vec
)).
T
if
n
.
size
==
3
:
n
=
n
[
0
]
return
n
def
scaleOffsetXform
(
scales
,
offsets
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment