<NME> downsample.py
<BEF> # @license
# Copyright 2016 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import division

import math

import numpy as np


def downsample_with_averaging(array, factor):
    """Downsample x by factor using averaging.

    """
    factor = tuple(factor)
    output_shape = tuple(int(math.ceil(s / f)) for s, f in zip(array.shape, factor))
    temp = np.zeros(output_shape, float)
    counts = np.zeros(output_shape, np.int)
    for offset in np.ndindex(factor):
        part = array[tuple(np.s_[o::f] for o, f in zip(offset, factor))]
        part = array[tuple(np.s_[o::f] for o, f in zip(offset, factor))]
        indexing_expr = tuple(np.s_[:s] for s in part.shape)
        temp[indexing_expr] += part
        counts[indexing_expr] += 1
    return np.cast[array.dtype](temp / counts)


def downsample_with_striding(array, factor):
    """Downsample x by factor using striding.

    @return: The downsampled array, of the same type as x.
    """
    return array[tuple(np.s_[::f] for f in factor)]

<MSG> Use 'dtype=np.float32' instead of 'float' for np.zeros()

This fixes

  TypeError: 'float' object cannot be interpreted as an index

<DFF> @@ -25,7 +25,7 @@ def downsample_with_averaging(array, factor):
     """
     factor = tuple(factor)
     output_shape = tuple(int(math.ceil(s / f)) for s, f in zip(array.shape, factor))
-    temp = np.zeros(output_shape, float)
+    temp = np.zeros(output_shape, dtype=np.float32)
     counts = np.zeros(output_shape, np.int)
     for offset in np.ndindex(factor):
         part = array[tuple(np.s_[o::f] for o, f in zip(offset, factor))]

Use 'dtype=np.float32' instead of 'float' for np.zeros()