MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / cast_to_floatx

Function cast_to_floatx

tensorflow/python/keras/backend.py:151–175  ·  view source on GitHub ↗

Cast a Numpy array to the default Keras float type. Arguments: x: Numpy array. Returns: The same Numpy array, cast to its new type. Example: ```python >>> from tensorflow.keras import backend as K >>> K.floatx() 'float32' >>> arr = numpy.array([1.0, 2.0

(x)

Source from the content-addressed store, hash-verified

149
150@keras_export('keras.backend.cast_to_floatx')
151def cast_to_floatx(x):
152 """Cast a Numpy array to the default Keras float type.
153
154 Arguments:
155 x: Numpy array.
156
157 Returns:
158 The same Numpy array, cast to its new type.
159
160 Example:
161 ```python
162 >>> from tensorflow.keras import backend as K
163 >>> K.floatx()
164 'float32'
165 >>> arr = numpy.array([1.0, 2.0], dtype='float64')
166 >>> arr.dtype
167 dtype('float64')
168 >>> new_arr = K.cast_to_floatx(arr)
169 >>> new_arr
170 array([ 1., 2.], dtype=float32)
171 >>> new_arr.dtype
172 dtype('float32')
173 ```
174 """
175 return np.asarray(x, dtype=floatx())
176
177
178# A global dictionary mapping graph objects to an index of counters used

Callers

nothing calls this directly

Calls 1

floatxFunction · 0.85

Tested by

no test coverage detected