

def _fix_unknown_dimension(self, input_shape, output_shape):
    'Find and replace a single missing dimension in an output shape\n        given an input shape.\n\n        A near direct port of the internal numpy function _fix_unknown_dimension\n        in numpy/core/src/multiarray/shape.c\n\n        # Arguments\n            input_shape: shape of array being reshaped\n\n            output_shape: desired shape of the array with at most\n                a single -1 which indicates a dimension that should be\n                derived from the input shape.\n\n        # Returns\n            The new output shape with a -1 replaced with its computed value.\n\n            Raises a ValueError if the total array size of the output_shape is\n            different then the input_shape, or more then one unknown dimension\n            is specified.\n        '
    output_shape = list(output_shape)
    msg = 'total size of new array must be unchanged'
    (known, unknown) = (1, None)
    for (index, dim) in enumerate(output_shape):
        if (dim < 0):
            if (unknown is None):
                unknown = index
            else:
                raise ValueError('can only specify one unknown dimension')
        else:
            known *= dim
    original = np.prod(input_shape, dtype=int)
    if (unknown is not None):
        if ((known == 0) or ((original % known) != 0)):
            raise ValueError(msg)
        output_shape[unknown] = (original // known)
    elif (original != known):
        raise ValueError(msg)
    return tuple(output_shape)

dataset/ETHPy150Open fchollet/keras/keras/layers/core.py Reshape._fix_unknown_dimension/original