몇몇 독자는 성능을 희생하지 않으면서 한 축에 대해 평균값을 빼는 과정을 일반화할 수 없을
지 궁금할 것이다. 사실 방법이 존재하긴 하지만 색인을 이용한 약간의 서커스가 필요하다.
def demean
_
axis
(
arr
,
axis
=
0
):
means
=
arr
.
mean
(
axis
)
#
이렇게
n
차원에
대해서
[:,
:,
np
.
newaxis
]
를
수행하는
과정을
일반화할
수
있다
.
indexer
=
[
slice
(
None
)]
*
arr
.
ndim
indexer
[
axis
]
=
np
.
newaxis
return ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.