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
funpack
Commits
7fd7041b
Commit
7fd7041b
authored
Feb 18, 2020
by
Paul McCarthy
🚵
Browse files
ENH: Speed up binariseCategorical with take by > 1000%
parent
426683af
Changes
1
Hide whitespace changes
Inline
Side-by-side
funpack/processing_functions_core.py
View file @
7fd7041b
...
...
@@ -319,13 +319,18 @@ def binariseCategorical(data, minpres=None, take=None):
# every column in it has the same dtype
binshape
=
(
len
(
data
),
len
(
uniq
))
if
take
is
None
:
bindata
=
np
.
zeros
(
binshape
,
dtype
=
np
.
uint8
)
else
:
bindata
=
np
.
zeros
(
binshape
,
dtype
=
take
.
dtypes
[
0
])
else
:
bindata
=
np
.
full
(
binshape
,
np
.
nan
,
dtype
=
take
.
dtypes
[
0
])
for
i
,
v
in
enumerate
(
uniq
):
mask
=
data
==
v
if
take
is
None
:
values
=
mask
.
any
(
axis
=
1
)
else
:
values
=
take
.
where
(
mask
.
values
).
apply
(
first
,
axis
=
1
)
bindata
[:,
i
]
=
values
if
take
is
None
:
bindata
[:,
i
]
=
mask
.
any
(
axis
=
1
)
else
:
rowmask
=
mask
.
any
(
axis
=
1
)
idxs
=
np
.
argmax
(
mask
.
values
,
axis
=
1
)
values
=
take
.
values
[
np
.
arange
(
take
.
shape
[
0
]),
idxs
]
bindata
[
rowmask
,
i
]
=
values
[
rowmask
]
return
bindata
,
uniq
...
...
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