emat/util/one_hot.py
def _to_categorical(y, num_classes=None, dtype='float32', compress=False):
	"""Converts a class array (integers) to binary class array.

	E.g. for use with categorical_crossentropy.

	Args:
		y (array-like): class array to be converted
			(integers from 0 to num_classes).
		num_classes (int, optional): total number of classes.  If not given, the
			number of classes is the maximum value found in `y` plus 1, or the
			actual number of unique values if `compress` is True.
		dtype (str, optional): The data type to be returned,
			(e.g. `float32`, `float64`, `int32`...)
		compress (bool, default False): Whether to compress the values in the input
			array, so that only classes with at least one observation appear
			in the result.  This is useful if the input array is not encoded with
			a sequential set of integer values.


	Returns:
		ndarray: A binary matrix representation of the input. The classes axis
			is placed last, such that the shape of this array is the same as that
			of `y` plus one dimension.

	"""
	y = numpy.array(y, dtype='int')
	if compress:
		y = numpy.unique(y, return_inverse=True)[1]
	input_shape = y.shape
	if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:
		input_shape = tuple(input_shape[:-1])
	y = y.ravel()
	if not num_classes:
		num_classes = numpy.max(y) + 1
	n = y.shape[0]
	categorical = numpy.zeros((n, num_classes), dtype=dtype)
	categorical[numpy.arange(n), y] = 1
	output_shape = input_shape + (num_classes,)
	categorical = numpy.reshape(categorical, output_shape)
	return categorical
Converts a class array (integers) to binary class array.

	E.g. for use with categorical_crossentropy.

	Args:
		y (array-like): class array to be converted
			(integers from 0 to num_classes).
		num_classes (int, optional): total number of classes.  If not given, the
			number of classes is the maximum value found in `y` plus 1, or the
			actual number of unique values if `compress` is True.
		dtype (str, optional): The data type to be returned,
			(e.g. `float32`, `float64`, `int32`...)
		compress (bool, default False): Whether to compress the values in the input
			array, so that only classes with at least one observation appear
			in the result.  This is useful if the input array is not encoded with
			a sequential set of integer values.


	Returns:
		ndarray: A binary matrix representation of the input. The classes axis
			is placed last, such that the shape of this array is the same as that
			of `y` plus one dimension.

	
Converts a class array (integers) to binary class array.
Converts a class array ( integers ) to binary class array .
def _to_categorical(y, num_classes=None, dtype='float32', compress=False):
	y = numpy.array(y, dtype='int')
	if compress:
		y = numpy.unique(y, return_inverse=True)[1]
	input_shape = y.shape
	if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:
		input_shape = tuple(input_shape[:-1])
	y = y.ravel()
	if not num_classes:
		num_classes = numpy.max(y) + 1
	n = y.shape[0]
	categorical = numpy.zeros((n, num_classes), dtype=dtype)
	categorical[numpy.arange(n), y] = 1
	output_shape = input_shape + (num_classes,)
	categorical = numpy.reshape(categorical, output_shape)
	return categorical
def _to_categorical ( y , num_classes = None , dtype = 'float32' , compress = False ) : y = numpy . array ( y , dtype = 'int' ) if compress : y = numpy . unique ( y , return_inverse = True ) [ 1 ] input_shape = y . shape if input_shape and input_shape [ - 1 ] == 1 and len ( input_shape ) > 1 : input_shape = tuple ( input_shape [ : - 1 ] ) y = y . ravel ( ) if not num_classes : num_classes = numpy . max ( y ) + 1 n = y . shape [ 0 ] categorical = numpy . zeros ( ( n , num_classes ) , dtype = dtype ) categorical [ numpy . arange ( n ) , y ] = 1 output_shape = input_shape + ( num_classes , ) categorical = numpy . reshape ( categorical , output_shape ) return categorical
Converts a class array (integers) to binary class array.
Converts a class array ( integers ) to binary class array .
"""Converts a class array (integers) to binary class array.

	E.g. for use with categorical_crossentropy.

	Args:
		y (array-like): class array to be converted
			(integers from 0 to num_classes).
		num_classes (int, optional): total number of classes.  If not given, the
			number of classes is the maximum value found in `y` plus 1, or the
			actual number of unique values if `compress` is True.
		dtype (str, optional): The data type to be returned,
			(e.g. `float32`, `float64`, `int32`...)
		compress (bool, default False): Whether to compress the values in the input
			array, so that only classes with at least one observation appear
			in the result.  This is useful if the input array is not encoded with
			a sequential set of integer values.


	Returns:
		ndarray: A binary matrix representation of the input. The classes axis
			is placed last, such that the shape of this array is the same as that
			of `y` plus one dimension.

	"""
A binary matrix representation of the input. The classes axis
is placed last, such that the shape of this array is the same as that
of `y` plus one dimension.
A binary matrix representation of the input . The classes axis is placed last such that the shape of this array is the same as that of ` y ` plus one dimension .
ndarray
y
class array to be converted
(integers from 0 to num_classes).
class array to be converted ( integers from 0 to num_classes ) .
num_classes
total number of classes.  If not given, the
number of classes is the maximum value found in `y` plus 1, or the
actual number of unique values if `compress` is True.
total number of classes . If not given the number of classes is the maximum value found in ` y ` plus 1 or the actual number of unique values if ` compress ` is True .
dtype
The data type to be returned.
The data type to be returned .
compress
Whether to compress the values in the input
array, so that only classes with at least one observation appear
in the result.  This is useful if the input array is not encoded with
a sequential set of integer values.
Whether to compress the values in the input array so that only classes with at least one observation appear in the result . This is useful if the input array is not encoded with a sequential set of integer values .