@@ -306,18 +306,21 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
306
306
out_height = int (out_height_base )
307
307
308
308
if not unsampled :
309
- if len ( A . shape ) == 2 :
309
+ if A . ndim == 2 :
310
310
A = self .norm (A )
311
311
if A .dtype .kind == 'f' :
312
312
# For floating-point greyscale images, we treat negative
313
313
# numbers as transparent.
314
+
315
+ # TODO: Use np.full when we support Numpy 1.9 as a
316
+ # minimum
314
317
output = np .empty ((out_height , out_width ), dtype = A .dtype )
315
318
output [...] = - 100.0
316
319
else :
317
320
output = np .zeros ((out_height , out_width ), dtype = A .dtype )
318
321
319
322
alpha = 1.0
320
- elif len ( A . shape ) == 3 :
323
+ elif A . ndim == 3 :
321
324
# Always convert to RGBA, even if only RGB input
322
325
if A .shape [2 ] == 3 :
323
326
A = _rgb_to_rgba (A )
@@ -340,7 +343,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
340
343
output = self .to_rgba (output , bytes = True , norm = False )
341
344
342
345
# Apply alpha *after* if the input was greyscale
343
- if len ( A . shape ) == 2 :
346
+ if A . ndim == 2 :
344
347
alpha = self .get_alpha ()
345
348
if alpha is not None and alpha != 1.0 :
346
349
alpha_channel = output [:, :, 3 ]
@@ -715,7 +718,7 @@ def make_image(self, renderer, magnification=1.0):
715
718
raise RuntimeError ('You must first set the image array' )
716
719
717
720
A = self ._A
718
- if len ( A . shape ) == 2 :
721
+ if A . ndim == 2 :
719
722
if A .dtype != np .uint8 :
720
723
A = self .to_rgba (A , bytes = True )
721
724
self .is_grayscale = self .cmap .is_gray ()
@@ -763,12 +766,12 @@ def set_data(self, x, y, A):
763
766
if len (x .shape ) != 1 or len (y .shape ) != 1 \
764
767
or A .shape [0 :2 ] != (y .shape [0 ], x .shape [0 ]):
765
768
raise TypeError ("Axes don't match array shape" )
766
- if len ( A . shape ) not in [2 , 3 ]:
769
+ if A . ndim not in [2 , 3 ]:
767
770
raise TypeError ("Can only plot 2D or 3D data" )
768
- if len ( A . shape ) == 3 and A .shape [2 ] not in [1 , 3 , 4 ]:
771
+ if A . ndim == 3 and A .shape [2 ] not in [1 , 3 , 4 ]:
769
772
raise TypeError ("3D arrays must have three (RGB) "
770
773
"or four (RGBA) color components" )
771
- if len ( A . shape ) == 3 and A .shape [2 ] == 1 :
774
+ if A . ndim == 3 and A .shape [2 ] == 1 :
772
775
A .shape = A .shape [0 :2 ]
773
776
self ._A = A
774
777
self ._Ax = x
0 commit comments