def guess_spatial_dimensions(image):
 if (image.ndim == 2):
  return 2
 if ((image.ndim == 3) and (image.shape[(-1)] != 3)):
  return 3
 if ((image.ndim == 3) and (image.shape[(-1)] == 3)):
  return None
 if ((image.ndim == 4) and (image.shape[(-1)] == 3)):
  return 3
 else:
  raise ValueError(('Expected 2D, 3D, or 4D array, got %iD.' % image.ndim))

def guess_spatial_dimensions ( image ) : if ( image . ndim == 2 ) : return 2 if ( ( image . ndim == 3 ) and ( image . shape [ ( - 1 ) ] != 3 ) ) : return 3 if ( ( image . ndim == 3 ) and ( image . shape [ ( - 1 ) ] == 3 ) ) : return None if ( ( image . ndim == 4 ) and ( image . shape [ ( - 1 ) ] == 3 ) ) : return 3 else : raise ValueError ( ( 'Expected 2D, 3D, or 4D array, got %iD.' % image . ndim ) )
make an educated guess about whether an image has a channels dimension .