Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb0a4cf

Browse files
committed
Normalize: major speed-up via bypassing masked array division
svn path=/trunk/matplotlib/; revision=8965
1 parent c8c5c32 commit fb0a4cf

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

lib/matplotlib/colors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,11 @@ def __call__(self, value, clip=None):
853853
mask = ma.getmask(result)
854854
result = ma.array(np.clip(result.filled(vmax), vmin, vmax),
855855
mask=mask)
856-
result -= vmin
857-
result /= vmax - vmin
856+
# ma division is very slow; we can take a shortcut
857+
resdat = result.data
858+
resdat -= vmin
859+
resdat /= (vmax - vmin)
860+
result = np.ma.array(resdat, mask=result.mask, copy=False)
858861
if is_scalar:
859862
result = result[0]
860863
return result

0 commit comments

Comments
 (0)