abs functionkeras.ops.abs(x)Shorthand forkeras.ops.absolute.
absolute functionkeras.ops.absolute(x)Compute the absolute value element-wise.
keras.ops.abs is a shorthand for this function.
Arguments
Returns
An array containing the absolute value of each element inx.
Example
>>>x=keras.ops.convert_to_tensor([-1.2,1.2])>>>keras.ops.absolute(x)array([1.2,1.2],dtype=float32)add functionkeras.ops.add(x1,x2)Add arguments element-wise.
Arguments
Returns
The tensor containing the element-wise sum ofx1 andx2.
Examples
>>>x1=keras.ops.convert_to_tensor([1,4])>>>x2=keras.ops.convert_to_tensor([5,6])>>>keras.ops.add(x1,x2)array([6,10],dtype=int32)keras.ops.add also broadcasts shapes:
>>>x1=keras.ops.convert_to_tensor(...[[5,4],...[5,6]]...)>>>x2=keras.ops.convert_to_tensor([5,6])>>>keras.ops.add(x1,x2)array([[1010][1012]],shape=(2,2),dtype=int32)all functionkeras.ops.all(x,axis=None,keepdims=False)Test whether all array elements along a given axis evaluate toTrue.
Arguments
axis=None) is to perform a logical AND over all the dimensions of the input array.axis may be negative, in which case it counts for the last to the first axis.True, axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. Defaults toFalse.Returns
The tensor containing the logical AND reduction over theaxis.
Examples
>>>x=keras.ops.convert_to_tensor([True,False])>>>keras.ops.all(x)array(False,shape=(),dtype=bool)>>>x=keras.ops.convert_to_tensor([[True,False],[True,True]])>>>keras.ops.all(x,axis=0)array([TrueFalse],shape=(2,),dtype=bool)keepdims=True outputs a tensor with dimensions reduced to one.
>>>x=keras.ops.convert_to_tensor([[True,False],[True,True]])>>>keras.ops.all(x,keepdims=True)array([[False]],shape=(1,1),dtype=bool)amax functionkeras.ops.amax(x,axis=None,keepdims=False)Returns the maximum of an array or maximum value along an axis.
Arguments
axis=None), find the maximum value in all the dimensions of the input array.True, axes which are reduced are left in the result as dimensions that are broadcast to the size of the original input tensor. Defaults toFalse.Returns
An array with the maximum value. Ifaxis=None, the result is a scalarvalue representing the maximum element in the entire array. Ifaxis isgiven, the result is an array with the maximum values alongthe specified axis.
Examples
>>>x=keras.ops.convert_to_tensor([[1,3,5],[2,3,6]])>>>keras.ops.amax(x)array(6,dtype=int32)>>>x=keras.ops.convert_to_tensor([[1,6,8],[1,5,2]])>>>keras.ops.amax(x,axis=0)array([1,6,8],dtype=int32)>>>x=keras.ops.convert_to_tensor([[1,6,8],[1,5,2]])>>>keras.ops.amax(x,axis=1,keepdims=True)array([[8],[5]],dtype=int32)amin functionkeras.ops.amin(x,axis=None,keepdims=False)Returns the minimum of an array or minimum value along an axis.
Arguments
axis=None), find the minimum value in all the dimensions of the input array.True, axes which are reduced are left in the result as dimensions that are broadcast to the size of the original input tensor. Defaults toFalse.Returns
An array with the minimum value. Ifaxis=None, the result is a scalarvalue representing the minimum element in the entire array. Ifaxis isgiven, the result is an array with the minimum values alongthe specified axis.
Examples
>>>x=keras.ops.convert_to_tensor([1,3,5,2,3,6])>>>keras.ops.amin(x)array(1,dtype=int32)>>>x=keras.ops.convert_to_tensor([[1,6,8],[7,5,3]])>>>keras.ops.amin(x,axis=0)array([1,5,3],dtype=int32)>>>x=keras.ops.convert_to_tensor([[1,6,8],[7,5,3]])>>>keras.ops.amin(x,axis=1,keepdims=True)array([[1],[3]],dtype=int32)angle functionkeras.ops.angle(x)Element-wise angle of a complex tensor.
Arguments
Returns
Output tensor of same shape as x. containing the angle of each element(in radians).
Example
>>>x=keras.ops.convert_to_tensor([[1+3j,2-5j],[4-3j,3+2j]])>>>keras.ops.angle(x)array([[1.2490457,-1.19029],[-0.6435011,0.5880026]],dtype=float32)any functionkeras.ops.any(x,axis=None,keepdims=False)Test whether any array element along a given axis evaluates toTrue.
Arguments
axis=None) is to perform a logical OR over all the dimensions of the input array.axis may be negative, in which case it counts for the last to the first axis.True, axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. Defaults toFalse.Returns
The tensor containing the logical OR reduction over theaxis.
Examples
>>>x=keras.ops.convert_to_tensor([True,False])>>>keras.ops.any(x)array(True,shape=(),dtype=bool)>>>x=keras.ops.convert_to_tensor([[True,False],[True,True]])>>>keras.ops.any(x,axis=0)array([TrueTrue],shape=(2,),dtype=bool)keepdims=True outputs a tensor with dimensions reduced to one.
>>>x=keras.ops.convert_to_tensor([[True,False],[True,True]])>>>keras.ops.all(x,keepdims=True)array([[False]],shape=(1,1),dtype=bool)append functionkeras.ops.append(x1,x2,axis=None)Append tensorx2 to the end of tensorx1.
Arguments
x2 is appended to tensorx1. IfNone, both tensors are flattened before use.Returns
A tensor with the values ofx2 appended tox1.
Examples
>>>x1=keras.ops.convert_to_tensor([1,2,3])>>>x2=keras.ops.convert_to_tensor([[4,5,6],[7,8,9]])>>>keras.ops.append(x1,x2)array([1,2,3,4,5,6,7,8,9],dtype=int32)Whenaxis is specified,x1 andx2 must have compatible shapes.
>>>x1=keras.ops.convert_to_tensor([[1,2,3],[4,5,6]])>>>x2=keras.ops.convert_to_tensor([[7,8,9]])>>>keras.ops.append(x1,x2,axis=0)array([[1,2,3],[4,5,6],[7,8,9]],dtype=int32)>>>x3=keras.ops.convert_to_tensor([7,8,9])>>>keras.ops.append(x1,x3,axis=0)Traceback(mostrecentcalllast):...TypeError:Cannotconcatenatearrayswithdifferentnumbersofdimensions:got(2,3),(3,).arange functionkeras.ops.arange(start,stop=None,step=None,dtype=None)Return evenly spaced values within a given interval.
arange can be called with a varying number of positional arguments:*arange(stop): Values are generated within the half-open interval[0, stop) (in other words, the interval including start but excluding stop).*arange(start, stop): Values are generated within the half-open interval[start, stop).*arange(start, stop, step): Values are generated within the half-open interval[start, stop), with spacing between values given by step.
Arguments
step is not an integer and floating point round-off affects the length ofout. Defaults toNone.out, this is the distance between two adjacent values,out[i+1] - out[i]. The default step size is 1. Ifstep is specified as a position argument,start must also be given.dtype is not given, infer the data type from the other input arguments.Returns
Tensor of evenly spaced values.For floating point arguments, the length of the result isceil((stop - start)/step). Because of floating point overflow, thisrule may result in the last element of out being greater than stop.
Examples
>>>keras.ops.arange(3)array([0,1,2],dtype=int32)>>>keras.ops.arange(3.0)array([0.,1.,2.],dtype=float32)>>>keras.ops.arange(3,7)array([3,4,5,6],dtype=int32)>>>keras.ops.arange(3,7,2)array([3,5],dtype=int32)arccos functionkeras.ops.arccos(x)Trigonometric inverse cosine, element-wise.
The inverse ofcos so that, ify = cos(x), thenx = arccos(y).
Arguments
Returns
Tensor of the angle of the ray intersecting the unit circle at the givenx-coordinate in radians[0, pi].
Example
>>>x=keras.ops.convert_to_tensor([1,-1])>>>keras.ops.arccos(x)array([0.0,3.1415927],dtype=float32)arccosh functionkeras.ops.arccosh(x)Inverse hyperbolic cosine, element-wise.
Arguments
Returns
Output tensor of same shape as x.
Example
>>>x=keras.ops.convert_to_tensor([10,100])>>>keras.ops.arccosh(x)array([2.993223,5.298292],dtype=float32)arcsin functionkeras.ops.arcsin(x)Inverse sine, element-wise.
Arguments
Returns
Tensor of the inverse sine of each element inx, in radians and inthe closed interval[-pi/2, pi/2].
Example
>>>x=keras.ops.convert_to_tensor([1,-1,0])>>>keras.ops.arcsin(x)array([1.5707964,-1.5707964,0.],dtype=float32)arcsinh functionkeras.ops.arcsinh(x)Inverse hyperbolic sine, element-wise.
Arguments
Returns
Output tensor of same shape asx.
Example
>>>x=keras.ops.convert_to_tensor([1,-1,0])>>>keras.ops.arcsinh(x)array([0.88137364,-0.88137364,0.0],dtype=float32)arctan functionkeras.ops.arctan(x)Trigonometric inverse tangent, element-wise.
Arguments
Returns
Tensor of the inverse tangent of each element inx, in the interval[-pi/2, pi/2].
Example
>>>x=keras.ops.convert_to_tensor([0,1])>>>keras.ops.arctan(x)array([0.,0.7853982],dtype=float32)arctan2 functionkeras.ops.arctan2(x1,x2)Element-wise arc tangent ofx1/x2 choosing the quadrant correctly.
The quadrant (i.e., branch) is chosen so thatarctan2(x1, x2) is thesigned angle in radians between the ray ending at the origin and passingthrough the point(1, 0), and the ray ending at the origin and passingthrough the point(x2, x1). (Note the role reversal: the "y-coordinate"is the first function parameter, the "x-coordinate" is the second.) By IEEEconvention, this function is defined forx2 = +/-0 and for either or bothofx1 andx2= +/-inf.
Arguments
Returns
Tensor of angles in radians, in the range[-pi, pi].
Examples
Consider four points in different quadrants:
>>>x=keras.ops.convert_to_tensor([-1,+1,+1,-1])>>>y=keras.ops.convert_to_tensor([-1,-1,+1,+1])>>>keras.ops.arctan2(y,x)*180/numpy.piarray([-135.,-45.,45.,135.],dtype=float32)Note the order of the parameters.arctan2 is defined also when x2=0 andat several other points, obtaining values in the range[-pi, pi]:
>>>keras.ops.arctan2(...keras.ops.array([1.,-1.]),...keras.ops.array([0.,0.]),...)array([1.5707964,-1.5707964],dtype=float32)>>>keras.ops.arctan2(...keras.ops.array([0.,0.,numpy.inf]),...keras.ops.array([+0.,-0.,numpy.inf]),...)array([0.,3.1415925,0.7853982],dtype=float32)arctanh functionkeras.ops.arctanh(x)Inverse hyperbolic tangent, element-wise.
Arguments
Returns
Output tensor of same shape asx.
argmax functionkeras.ops.argmax(x,axis=None,keepdims=False)Returns the indices of the maximum values along an axis.
Arguments
True, the axes which are reduced are left in the result as dimensions with size one. Defaults toFalse.Returns
Tensor of indices. It has the same shape asx, with the dimensionalongaxis removed.
Example
>>>x=keras.ops.arange(6).reshape(2,3)+10>>>xarray([[10,11,12],[13,14,15]],dtype=int32)>>>keras.ops.argmax(x)array(5,dtype=int32)>>>keras.ops.argmax(x,axis=0)array([1,1,1],dtype=int32)>>>keras.ops.argmax(x,axis=1)array([2,2],dtype=int32)argmin functionkeras.ops.argmin(x,axis=None,keepdims=False)Returns the indices of the minimum values along an axis.
Arguments
True, the axes which are reduced are left in the result as dimensions with size one. Defaults toFalse.Returns
Tensor of indices. It has the same shape asx, with the dimensionalongaxis removed.
Example
>>>x=keras.ops.arange(6).reshape(2,3)+10>>>xarray([[10,11,12],[13,14,15]],dtype=int32)>>>keras.ops.argmin(x)array(0,dtype=int32)>>>keras.ops.argmin(x,axis=0)array([0,0,0],dtype=int32)>>>keras.ops.argmin(x,axis=1)array([0,0],dtype=int32)argpartition functionkeras.ops.argpartition(x,kth,axis=-1)Performs an indirect partition along the given axis.
It returns an arrayof indices of the same shape asx that index data along the given axisin partitioned order.
Arguments
None, the flattened array is used.Returns
Array of indices that partitionx along the specifiedaxis.
argsort functionkeras.ops.argsort(x,axis=-1)Returns the indices that would sort a tensor.
Arguments
-1 (the last axis). IfNone, the flattened tensor is used.Returns
Tensor of indices that sortx along the specifiedaxis.
Examples
One dimensional array:
>>>x=keras.ops.array([3,1,2])>>>keras.ops.argsort(x)array([1,2,0],dtype=int32)Two-dimensional array:
>>>x=keras.ops.array([[0,3],[3,2],[4,5]])>>>xarray([[0,3],[3,2],[4,5]],dtype=int32)>>>keras.ops.argsort(x,axis=0)array([[0,1],[1,0],[2,2]],dtype=int32)>>>keras.ops.argsort(x,axis=1)array([[0,1],[1,0],[0,1]],dtype=int32)array functionkeras.ops.array(x,dtype=None)Create a tensor.
Arguments
Returns
A tensor.
Examples
>>>keras.ops.array([1,2,3])array([1,2,3],dtype=int32)>>>keras.ops.array([1,2,3],dtype="float32")array([1.,2.,3.],dtype=float32)average functionkeras.ops.average(x,axis=None,weights=None)Compute the weighted average along the specified axis.
Arguments
x. The default,axis=None, will average over all of the elements of the input tensor. If axis is negative it counts from the last to the first axis.x. Each value inx contributes to the average according to its associated weight. The weights array can either be 1-D (in which case its length must be the size of a along the given axis) or of the same shape asx. Ifweights=None (default), then all data inx are assumed to have a weight equal to one.avg = sum(a * weights) / sum(weights). The only constraint on weights is thatsum(weights) must not be 0.Returns
Return the average along the specified axis.
Examples
>>>data=keras.ops.arange(1,5)>>>dataarray([1,2,3,4],dtype=int32)>>>keras.ops.average(data)array(2.5,dtype=float32)>>>keras.ops.average(...keras.ops.arange(1,11),...weights=keras.ops.arange(10,0,-1)...)array(4.,dtype=float32)>>>data=keras.ops.arange(6).reshape((3,2))>>>dataarray([[0,1],[2,3],[4,5]],dtype=int32)>>>keras.ops.average(...data,...axis=1,...weights=keras.ops.array([1./4,3./4])...)array([0.75,2.75,4.75],dtype=float32)>>>keras.ops.average(...data,...weights=keras.ops.array([1./4,3./4])...)Traceback(mostrecentcalllast):...ValueError:Axismustbespecifiedwhenshapesofaandweightsdiffer.bartlett functionkeras.ops.bartlett(x)Bartlett window function.The Bartlett window is a triangular window that rises then falls linearly.
Arguments
Returns
A 1D tensor containing the Bartlett window values.
Example
>>>x=keras.ops.convert_to_tensor(5)>>>keras.ops.bartlett(x)array([0.,0.5,1.,0.5,0.],dtype=float32)bincount functionkeras.ops.bincount(x,weights=None,minlength=0,sparse=False)Count the number of occurrences of each value in a tensor of integers.
Arguments
x. The default value isNone. If specified,x is weighted by it, i.e. ifn = x[i],out[n] += weight[i] instead of the default behaviorout[n] += 1.max(x) + 1, each value of the output at an index higher thanmax(x) is set to 0.Returns
1D tensor where each element gives the number of occurrence(s) of itsindex value in x. Its length is the maximum betweenmax(x) + 1 andminlength.
Examples
>>>x=keras.ops.array([1,2,2,3],dtype="uint8")>>>keras.ops.bincount(x)array([0,1,2,1],dtype=int32)>>>weights=x/2>>>weightsarray([0.5,1.,1.,1.5],dtype=float64)>>>keras.ops.bincount(x,weights=weights)array([0.,0.5,2.,1.5],dtype=float64)>>>minlength=(keras.ops.max(x).numpy()+1)+2# 6>>>keras.ops.bincount(x,minlength=minlength)array([0,1,2,1,0,0],dtype=int32)bitwise_and functionkeras.ops.bitwise_and(x,y)Compute the bit-wise AND of two arrays element-wise.
Computes the bit-wise AND of the underlying binary representation of theintegers in the input arrays. This ufunc implements the C/Python operator&.
Arguments
Returns
Result tensor.
bitwise_invert functionkeras.ops.bitwise_invert(x)Compute bit-wise inversion, or bit-wise NOT, element-wise.
Computes the bit-wise NOT of the underlying binary representation of theintegers in the input arrays. This ufunc implements the C/Python operator~.
Arguments
Returns
Result tensor.
bitwise_left_shift functionkeras.ops.bitwise_left_shift(x,y)Shift the bits of an integer to the left.
Bits are shifted to the left by appendingy 0s at the right ofx.Since the internal representation of numbers is in binary format, thisoperation is equivalent to multiplyingx by2**y.
Arguments
Returns
Result tensor.
bitwise_not functionkeras.ops.bitwise_not(x)Compute bit-wise inversion, or bit-wise NOT, element-wise.
Computes the bit-wise NOT of the underlying binary representation of theintegers in the input arrays. This ufunc implements the C/Python operator~.
Arguments
Returns
Result tensor.
bitwise_or functionkeras.ops.bitwise_or(x,y)Compute the bit-wise OR of two arrays element-wise.
Computes the bit-wise OR of the underlying binary representation of theintegers in the input arrays. This ufunc implements the C/Python operator|.
Arguments
Returns
Result tensor.
bitwise_right_shift functionkeras.ops.bitwise_right_shift(x,y)Shift the bits of an integer to the right.
Bits are shifted to the righty. Because the internal representation ofnumbers is in binary format, this operation is equivalent to dividingx by2**y.
Arguments
Returns
Result tensor.
bitwise_xor functionkeras.ops.bitwise_xor(x,y)Compute the bit-wise XOR of two arrays element-wise.
Computes the bit-wise XOR of the underlying binary representation of theintegers in the input arrays. This ufunc implements the C/Python operator^.
Arguments
Returns
Result tensor.
blackman functionkeras.ops.blackman(x)Blackman window function.The Blackman window is a taper formed by using a weighted cosine.
Arguments
Returns
A 1D tensor containing the Blackman window values.
Example
>>>x=keras.ops.convert_to_tensor(5)>>>keras.ops.blackman(x)array([-1.3877788e-17,3.4000000e-01,1.0000000e+00,3.4000000e-01,-1.3877788e-17],dtype=float32)broadcast_to functionkeras.ops.broadcast_to(x,shape)Broadcast a tensor to a new shape.
Arguments
i is interpreted as(i,).Returns
A tensor with the desired shape.
Examples
>>>x=keras.ops.array([1,2,3])>>>keras.ops.broadcast_to(x,(3,3))array([[1,2,3],[1,2,3],[1,2,3]])cbrt functionkeras.ops.cbrt(x)Computes the cube root of the input tensor, element-wise.
This operation returns the real-valued cube root ofx, handlingnegative numbers properly in the real domain.
Arguments
Returns
A tensor containing the cube root of each element inx.
ceil functionkeras.ops.ceil(x)Return the ceiling of the input, element-wise.
The ceil of the scalarx is the smallest integeri, such thati >= x.
Arguments
Returns
The ceiling of each element inx, with float dtype.
clip functionkeras.ops.clip(x,x_min,x_max)Clip (limit) the values in a tensor.
Given an interval, values outside the interval are clipped to theinterval edges. For example, if an interval of[0, 1] is specified,values smaller than 0 become 0, and values larger than 1 become 1.
Arguments
Returns
The clipped tensor.
concatenate functionkeras.ops.concatenate(xs,axis=0)Join a sequence of tensors along an existing axis.
Arguments
0.Returns
The concatenated tensor.
conj functionkeras.ops.conj(x)Shorthand forkeras.ops.conjugate.
conjugate functionkeras.ops.conjugate(x)Returns the complex conjugate, element-wise.
The complex conjugate of a complex number is obtained by changing the signof its imaginary part.
keras.ops.conj is a shorthand for this function.
Arguments
Returns
The complex conjugate of each element inx.
copy functionkeras.ops.copy(x)Returns a copy ofx.
Arguments
Returns
A copy ofx.
corrcoef functionkeras.ops.corrcoef(x)Compute the Pearson correlation coefficient matrix.
Arguments
(N, D), where N is the number of variables and D is the number of observations.Returns
A tensor of shape(N, N) representing the correlation matrix.
correlate functionkeras.ops.correlate(x1,x2,mode="valid")Compute the cross-correlation of two 1-dimensional tensors.
Arguments
valid,same orfull. By default the mode is set tovalid, which returns an output of length max(M, N) - min(M, N) + 1.same returns an output of length max(M, N).full mode returns the convolution at each point of overlap, with an output length of N+M-1Returns
Output tensor, cross-correlation ofx1 andx2.
cos functionkeras.ops.cos(x)Cosine, element-wise.
Arguments
Returns
The corresponding cosine values.
cosh functionkeras.ops.cosh(x)Hyperbolic cosine, element-wise.
Arguments
Returns
Output tensor of same shape asx.
count_nonzero functionkeras.ops.count_nonzero(x,axis=None)Counts the number of non-zero values inx along the givenaxis.
If no axis is specified then all non-zeros in the tensor are counted.
Arguments
None.Returns
int or tensor of ints.
Examples
>>>x=keras.ops.array([[0,1,7,0],[3,0,2,19]])>>>keras.ops.count_nonzero(x)5>>>keras.ops.count_nonzero(x,axis=0)array([1,1,2,1],dtype=int64)>>>keras.ops.count_nonzero(x,axis=1)array([2,3],dtype=int64)cross functionkeras.ops.cross(x1,x2,axisa=-1,axisb=-1,axisc=-1,axis=None)Returns the cross product of two (arrays of) vectors.
The cross product ofx1 andx2 in R^3 is a vectorperpendicular to bothx1 andx2. Ifx1 andx2 are arrays ofvectors, the vectors are defined by the last axis ofx1 andx2by default, and these axes can have dimensions 2 or 3.
Where the dimension of eitherx1 orx2 is 2, the third component ofthe input vector is assumed to be zero and the cross product calculatedaccordingly.
In cases where both input vectors have dimension 2, the z-component ofthe cross product is returned.
Arguments
x1 that defines the vector(s). Defaults to-1.x2 that defines the vector(s). Defaults to-1.x1,x2 and the result that defines the vector(s) and cross product(s). Overridesaxisa,axisb andaxisc.Note: Torch backend does not support two dimensional vectors, or the argumentsaxisa,axisb andaxisc. Useaxis instead.
Returns
Vector cross product(s).
cumprod functionkeras.ops.cumprod(x,axis=None,dtype=None)Return the cumulative product of elements along a given axis.
Arguments
Returns
Output tensor.
cumsum functionkeras.ops.cumsum(x,axis=None,dtype=None)Returns the cumulative sum of elements along a given axis.
Arguments
Returns
Output tensor.
deg2rad functionkeras.ops.deg2rad(x)Convert angles from degrees to radians.
The conversion is defined as:rad = deg * (π / 180)
Arguments
Returns
A tensor containing angles converted to radians.
Examples
>>>fromkerasimportops>>>ops.deg2rad(180.0)3.141592653589793>>>ops.deg2rad([0.0,90.0,180.0])array([0.,1.57079633,3.14159265])diag functionkeras.ops.diag(x,k=0)Extract a diagonal or construct a diagonal array.
Arguments
x is 2-D, returns the k-th diagonal ofx. Ifx is 1-D, return a 2-D tensor withx on the k-th diagonal.0. Usek > 0 for diagonals above the main diagonal, andk < 0 for diagonals below the main diagonal.Returns
The extracted diagonal or constructed diagonal tensor.
Examples
>>>fromkeras.srcimportops>>>x=ops.arange(9).reshape((3,3))>>>xarray([[0,1,2],[3,4,5],[6,7,8]])>>>ops.diag(x)array([0,4,8])>>>ops.diag(x,k=1)array([1,5])>>>ops.diag(x,k=-1)array([3,7])>>>ops.diag(ops.diag(x)))array([[0,0,0],[0,4,0],[0,0,8]])diagflat functionkeras.ops.diagflat(x,k=0)Create a two-dimensional array with the flattened input on the k-th diagonal.
Arguments
0. Usek > 0 for diagonals above the main diagonal, andk < 0 for diagonals below the main diagonal.Returns
A 2-D tensor with the flattened input on the specified diagonal.
diagonal functionkeras.ops.diagonal(x,offset=0,axis1=0,axis2=1)Return specified diagonals.
Ifx is 2-D, returns the diagonal ofx with the given offset, i.e., thecollection of elements of the formx[i, i+offset].
Ifx has more than two dimensions, the axes specified byaxis1andaxis2 are used to determine the 2-D sub-array whose diagonalis returned.
The shape of the resulting array can be determined by removingaxis1andaxis2 and appending an index to the right equal to the size ofthe resulting diagonals.
Arguments
0.(main diagonal).0.(first axis).1 (second axis).Returns
Tensor of diagonals.
Examples
>>>fromkeras.srcimportops>>>x=ops.arange(4).reshape((2,2))>>>xarray([[0,1],[2,3]])>>>x.diagonal()array([0,3])>>>x.diagonal(1)array([1])>>>x=ops.arange(8).reshape((2,2,2))>>>xarray([[[0,1],[2,3]],[[4,5],[6,7]]])>>>x.diagonal(0,0,1)array([[0,6],[1,7]])diff functionkeras.ops.diff(a,n=1,axis=-1)Calculate the n-th discrete difference along the given axis.
The first difference is given byout[i] = a[i+1] - a[i] alongthe given axis, higher differences are calculated by usingdiffrecursively.
Arguments
1.-1.(last axis).Returns
Tensor of diagonals.
Examples
>>>fromkeras.srcimportops>>>x=ops.convert_to_tensor([1,2,4,7,0])>>>ops.diff(x)array([1,2,3,-7])>>>ops.diff(x,n=2)array([1,1,-10])>>>x=ops.convert_to_tensor([[1,3,6,10],[0,5,6,8]])>>>ops.diff(x)array([[2,3,4],[5,1,2]])>>>ops.diff(x,axis=0)array([[-1,2,0,-2]])digitize functionkeras.ops.digitize(x,bins)Returns the indices of the bins to which each value inx belongs.
Arguments
Returns
Output array of indices, of same shape asx.
Example
>>>x=np.array([0.0,1.0,3.0,1.6])>>>bins=np.array([0.0,3.0,4.5,7.0])>>>keras.ops.digitize(x,bins)array([1,1,2,1])divide functionkeras.ops.divide(x1,x2)Divide arguments element-wise.
keras.ops.true_divide is an alias for this function.
Arguments
Returns
Output tensor, the quotientx1/x2, element-wise.
divide_no_nan functionkeras.ops.divide_no_nan(x1,x2)Safe element-wise division which returns 0 where the denominator is 0.
Arguments
Returns
The quotientx1/x2, element-wise, with zero where x2 is zero.
dot functionkeras.ops.dot(x1,x2)Dot product of two tensors.
x1 andx2 are 1-D tensors, it is inner product of vectors (without complex conjugation).x1 andx2 are 2-D tensors, it is matrix multiplication.x1 orx2 is 0-D (scalar), it is equivalent tox1 * x2.x1 is an N-D tensor andx2 is a 1-D tensor, it is a sum product over the last axis ofx1 andx2.x1 is an N-D tensor andx2 is an M-D tensor (whereM>=2), it is a sum product over the last axis ofx1 and the second-to-last axis ofx2:dot(x1, x2)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m]).Arguments
Note: Torch backend does not accept 0-D tensors as arguments.
Returns
Dot product ofx1 andx2.
einsum functionkeras.ops.einsum(subscripts,*operands,**kwargs)Evaluates the Einstein summation convention on the operands.
Arguments
-> is included as well as subscript labels of the precise output form.Returns
The calculation based on the Einstein summation convention.
Example
>>>fromkeras.srcimportops>>>a=ops.arange(25).reshape(5,5)>>>b=ops.arange(5)>>>c=ops.arange(6).reshape(2,3)Trace of a matrix:
>>>ops.einsum("ii",a)60>>>ops.einsum(a,[0,0])60>>>ops.trace(a)60Extract the diagonal:
>>>ops.einsum("ii -> i",a)array([0,6,12,18,24])>>>ops.einsum(a,[0,0],[0])array([0,6,12,18,24])>>>ops.diag(a)array([0,6,12,18,24])Sum over an axis:
>>>ops.einsum("ij -> i",a)array([10,35,60,85,110])>>>ops.einsum(a,[0,1],[0])array([10,35,60,85,110])>>>ops.sum(a,axis=1)array([10,35,60,85,110])For higher dimensional tensors summing a single axis can be donewith ellipsis:
>>>ops.einsum("...j -> ...",a)array([10,35,60,85,110])>>>np.einsum(a,[...,1],[...])array([10,35,60,85,110])Compute a matrix transpose or reorder any number of axes:
>>>ops.einsum("ji",c)array([[0,3],[1,4],[2,5]])>>>ops.einsum("ij -> ji",c)array([[0,3],[1,4],[2,5]])>>>ops.einsum(c,[1,0])array([[0,3],[1,4],[2,5]])>>>ops.transpose(c)array([[0,3],[1,4],[2,5]])Matrix vector multiplication:
>>>ops.einsum("ij, j",a,b)array([30,80,130,180,230])>>>ops.einsum(a,[0,1],b,[1])array([30,80,130,180,230])>>>ops.einsum("...j, j",a,b)array([30,80,130,180,230])empty functionkeras.ops.empty(shape,dtype=None)Return a tensor of given shape and type filled with uninitialized data.
Arguments
Returns
The empty tensor.
equal functionkeras.ops.equal(x1,x2)Returns(x1 == x2) element-wise.
Arguments
Returns
Output tensor, element-wise comparison ofx1 andx2.
exp functionkeras.ops.exp(x)Calculate the exponential of all elements in the input tensor.
Arguments
Returns
Output tensor, element-wise exponential ofx.
exp2 functionkeras.ops.exp2(x)Calculate the base-2 exponential of all elements in the input tensor.
Arguments
Returns
Output tensor, element-wise base-2 exponential ofx.
expand_dims functionkeras.ops.expand_dims(x,axis)Expand the shape of a tensor.
Insert a new axis at theaxis position in the expanded tensor shape.
Arguments
Returns
Output tensor with the number of dimensions increased.
expm1 functionkeras.ops.expm1(x)Calculateexp(x) - 1 for all elements in the tensor.
Arguments
Returns
Output tensor, element-wise exponential minus one.
eye functionkeras.ops.eye(N,M=None,k=0,dtype=None)Return a 2-D tensor with ones on the diagonal and zeros elsewhere.
Arguments
None, defaults toN.Returns
Tensor with ones on the k-th diagonal and zeros elsewhere.
flip functionkeras.ops.flip(x,axis=None)Reverse the order of elements in the tensor along the given axis.
The shape of the tensor is preserved, but the elements are reordered.
Arguments
axis=None, will flip over all of the axes of the input tensor.Returns
Output tensor with entries ofaxis reversed.
floor functionkeras.ops.floor(x)Return the floor of the input, element-wise.
The floor of the scalarx is the largest integeri, such thati <= x.
Arguments
Returns
Output tensor, element-wise floor ofx.
floor_divide functionkeras.ops.floor_divide(x1,x2)Returns the largest integer smaller or equal to the division of inputs.
Arguments
Returns
Output tensor,y = floor(x1/x2)
full functionkeras.ops.full(shape,fill_value,dtype=None)Return a new tensor of given shape and type, filled withfill_value.
Arguments
Returns
Output tensor.
full_like functionkeras.ops.full_like(x,fill_value,dtype=None)Return a full tensor with the same shape and type as the given tensor.
Arguments
Returns
Tensor offill_value with the same shape and type asx.
gcd functionkeras.ops.gcd(x1,x2)Greatest common divisor ofx1 andx2, element-wise.
Arguments
Returns
Output tensor, element-wise greatest common divisor ofx1 andx2.
get_item functionkeras.ops.get_item(x,key)Returnx[key].
greater functionkeras.ops.greater(x1,x2)Return the truth value ofx1 > x2 element-wise.
Arguments
Returns
Output tensor, element-wise comparison ofx1 andx2.
greater_equal functionkeras.ops.greater_equal(x1,x2)Return the truth value ofx1 >= x2 element-wise.
Arguments
Returns
Output tensor, element-wise comparison ofx1 andx2.
hamming functionkeras.ops.hamming(x)Hamming window function.
The Hamming window is defined as:w[n] = 0.54 - 0.46 * cos(2 * pi * n / (N - 1)) for0 <= n <= N - 1.
Arguments
Returns
A 1D tensor containing the Hamming window values.
Example
>>>x=keras.ops.convert_to_tensor(5)>>>keras.ops.hamming(x)array([0.08,0.54,1.,0.54,0.08],dtype=float32)hanning functionkeras.ops.hanning(x)Hanning window function.
The Hanning window is defined as:w[n] = 0.5 - 0.5 * cos(2 * pi * n / (N - 1)) for0 <= n <= N - 1.
Arguments
Returns
A 1D tensor containing the Hanning window values.
Example
>>>x=keras.ops.convert_to_tensor(5)>>>keras.ops.hanning(x)array([0.,0.5,1.,0.5,0.],dtype=float32)heaviside functionkeras.ops.heaviside(x1,x2)Heaviside step function.
The Heaviside step function is defined as:heaviside(x1, x2) = 0 if x1 < 0, 1 if x1 > 0, x2 if x1 == 0
Arguments
x1 == 0.Returns
A tensor with a shape determined by broadcastingx1 andx2.
Example
>>>x1=keras.ops.convert_to_tensor([-2.0,0.0,3.0])>>>x2=0.5>>>keras.ops.heaviside(x1,x2)array([0.,0.5,1.],dtype=float32)histogram functionkeras.ops.histogram(x,bins=10,range=None)Computes a histogram of the data tensorx.
Arguments
x.Returns
Example
>>>input_tensor=np.random.rand(8)>>>keras.ops.histogram(input_tensor)(array([1,1,1,0,0,1,2,1,0,1],dtype=int32),array([0.0189519,0.10294958,0.18694726,0.27094494,0.35494262,0.43894029,0.52293797,0.60693565,0.69093333,0.77493101,0.85892869]))hstack functionkeras.ops.hstack(xs)Stack tensors in sequence horizontally (column wise).
This is equivalent to concatenation along the first axis for 1-D tensors,and along the second axis for all other tensors.
Arguments
Returns
The tensor formed by stacking the given tensors.
hypot functionkeras.ops.hypot(x1,x2)Element-wise hypotenuse of right triangles with legsx1 andx2.
This is equivalent to computingsqrt(x1**2 + x2**2) element-wise,with shape determined by broadcasting.
Arguments
Returns
A tensor with a shape determined by broadcastingx1 andx2.
Example
>>>x1=keras.ops.convert_to_tensor([3.0,4.0,5.0])>>>x2=keras.ops.convert_to_tensor([4.0,3.0,12.0])>>>keras.ops.hypot(x1,x2)array([5.,5.,13.],dtype=float32)>>>x1=keras.ops.convert_to_tensor([[1,2],[3,4]])>>>x2=keras.ops.convert_to_tensor([1,1])>>>keras.ops.hypot(x1,x2)array([[1.414213562.23606798],[3.162277664.12310563]],dtype=float32)identity functionkeras.ops.identity(n,dtype=None)Return the identity tensor.
The identity tensor is a square tensor with ones on the main diagonal andzeros elsewhere.
Arguments
n x n output tensor.Returns
The identity tensor.
imag functionkeras.ops.imag(x)Return the imaginary part of the complex argument.
Arguments
Returns
The imaginary component of the complex argument.
inner functionkeras.ops.inner(x1,x2)Return the inner product of two tensors.
Ordinary inner product of vectors for 1-D tensors(without complex conjugation), in higher dimensionsa sum product over the last axes.
Multidimensional arrays are treated as vectors by flatteningall but their last axes. The resulting dot product is performedover their last axes.
Arguments
x1 andx2 must match.Returns
Output tensor. The shape of the output is determined bybroadcasting the shapes ofx1 andx2 after removingtheir last axes.
isclose functionkeras.ops.isclose(x1,x2,rtol=1e-05,atol=1e-08,equal_nan=False)Return whether two tensors are element-wise almost equal.
Arguments
True, element-wise NaNs are considered equal.Returns
Output boolean tensor.
isfinite functionkeras.ops.isfinite(x)Return whether a tensor is finite, element-wise.
Real values are finite when they are not NaN, not positive infinity, andnot negative infinity. Complex values are finite when both their realand imaginary parts are finite.
Arguments
Returns
Output boolean tensor.
isinf functionkeras.ops.isinf(x)Test element-wise for positive or negative infinity.
Arguments
Returns
Output boolean tensor.
isnan functionkeras.ops.isnan(x)Test element-wise for NaN and return result as a boolean tensor.
Arguments
Returns
Output boolean tensor.
isneginf functionkeras.ops.isneginf(x)Test element-wise for negative infinity.
Arguments
Returns
Output boolean tensor.
isposinf functionkeras.ops.isposinf(x)Test element-wise for positive infinity.
Arguments
Returns
Output boolean tensor.
isreal functionkeras.ops.isreal(x)Test element-wise for real numbers.
Arguments
Returns
Output boolean tensor.
Example
from keras import opsx = ops.array([1+1j, 1+0j, 4.5, 3, 2, 2j], dtype="complex64")ops.isreal(x)array([False, True, True, True, True, False])
kaiser functionkeras.ops.kaiser(x,beta)Kaiser window function.
The Kaiser window is defined as:w[n] = I0(beta * sqrt(1 - (2n / (N - 1) - 1)^2)) / I0(beta)where I0 is the modified zeroth-order Bessel function of the first kind.
Arguments
Returns
A 1D tensor containing the Kaiser window values.
Example
>>>x=keras.ops.convert_to_tensor(5)>>>keras.ops.kaiser(x,beta=14.0)array([7.7268669e-06,1.6493219e-01,1.0000000e+00,1.6493219e-01,7.7268669e-06],dtype=float32)kron functionkeras.ops.kron(x1,x2)Kronecker product ofx1 andx2.
Computes the Kronecker product of two input tensors. Ifx1 has shape(a0, a1, ..., an) andx2 has shape(b0, b1, ..., bn), then theoutput will have shape(a0*b0, a1*b1, ..., an*bn).
Arguments
Returns
A tensor representing the Kronecker product ofx1 andx2.
lcm functionkeras.ops.lcm(x1,x2)Least common multiple ofx1 andx2, element-wise.
Arguments
Returns
Output tensor, element-wise least common multiple ofx1 andx2.
Example
>>>x1=keras.ops.convert_to_tensor([2,3,4])>>>x2=keras.ops.convert_to_tensor([5,6,7])>>>keras.ops.lcm(x1,x2)array([10,6,28],dtype=int32)left_shift functionkeras.ops.left_shift(x,y)Shift the bits of an integer to the left.
Bits are shifted to the left by appendingy 0s at the right ofx.Since the internal representation of numbers is in binary format, thisoperation is equivalent to multiplyingx by2**y.
Arguments
Returns
Result tensor.
less functionkeras.ops.less(x1,x2)Return the truth value ofx1 < x2 element-wise.
Arguments
Returns
Output tensor, element-wise comparison ofx1 andx2.
less_equal functionkeras.ops.less_equal(x1,x2)Return the truth value ofx1 <= x2 element-wise.
Arguments
Returns
Output tensor, element-wise comparison ofx1 andx2.
linspace functionkeras.ops.linspace(start,stop,num=50,endpoint=True,retstep=False,dtype=None,axis=0)Return evenly spaced numbers over a specified interval.
Returnsnum evenly spaced samples, calculated over the interval[start, stop].
The endpoint of the interval can optionally be excluded.
Arguments
endpoint is set toFalse. In that case, the sequence consists of all but the last ofnum + 1 evenly spaced samples, so thatstop is excluded. Note that the step size changes whenendpoint isFalse.50. Must be non-negative.True,stop is the last sample. Otherwise, it is not included. Defaults toTrue.True, return(samples, step), wherestep is the spacing between samples.0.Note: Torch backend does not supportaxis argument.
Returns
A tensor of evenly spaced numbers.Ifretstep isTrue, returns(samples, step)
log functionkeras.ops.log(x)Natural logarithm, element-wise.
Arguments
Returns
Output tensor, element-wise natural logarithm ofx.
log10 functionkeras.ops.log10(x)Return the base 10 logarithm of the input tensor, element-wise.
Arguments
Returns
Output tensor, element-wise base 10 logarithm ofx.
log1p functionkeras.ops.log1p(x)Returns the natural logarithm of one plus thex, element-wise.
Calculateslog(1 + x).
Arguments
Returns
Output tensor, element-wise natural logarithm of1 + x.
log2 functionkeras.ops.log2(x)Base-2 logarithm ofx, element-wise.
Arguments
Returns
Output tensor, element-wise base-2 logarithm ofx.
logaddexp functionkeras.ops.logaddexp(x1,x2)Logarithm of the sum of exponentiations of the inputs.
Calculateslog(exp(x1) + exp(x2)).
Arguments
Returns
Output tensor, element-wise logarithm of the sum of exponentiationsof the inputs.
logical_and functionkeras.ops.logical_and(x1,x2)Computes the element-wise logical AND of the given input tensors.
Zeros are treated asFalse and non-zeros are treated asTrue.
Arguments
Returns
Output tensor, element-wise logical AND of the inputs.
logical_not functionkeras.ops.logical_not(x)Computes the element-wise NOT of the given input tensor.
Zeros are treated asFalse and non-zeros are treated asTrue.
Arguments
Returns
Output tensor, element-wise logical NOT of the input.
logical_or functionkeras.ops.logical_or(x1,x2)Computes the element-wise logical OR of the given input tensors.
Zeros are treated asFalse and non-zeros are treated asTrue.
Arguments
Returns
Output tensor, element-wise logical OR of the inputs.
logical_xor functionkeras.ops.logical_xor(x1,x2)Compute the truth value ofx1 XOR x2, element-wise.
Arguments
Returns
Output boolean tensor.
logspace functionkeras.ops.logspace(start,stop,num=50,endpoint=True,base=10,dtype=None,axis=0)Returns numbers spaced evenly on a log scale.
In linear space, the sequence starts atbase ** start and ends withbase ** stop (seeendpoint below).
Arguments
endpoint isFalse. In that case,num + 1 values are spaced over the interval in log-space, of which all but the last (a sequence of lengthnum) are returned.50.True,stop is the last sample. Otherwise, it is not included. Defaults toTrue.10.Note: Torch backend does not supportaxis argument.
Returns
A tensor of evenly spaced samples on a log scale.
matmul functionkeras.ops.matmul(x1,x2)Matrix product of two tensors.
Arguments
Returns
Output tensor, matrix product of the inputs.
max functionkeras.ops.max(x,axis=None,keepdims=False,initial=None)Return the maximum of a tensor or maximum along an axis.
Arguments
True, the axes which are reduced are left in the result as dimensions with size one. Defaults toFalse.None.Returns
Maximum ofx.
maximum functionkeras.ops.maximum(x1,x2)Element-wise maximum ofx1 andx2.
Arguments
Returns
Output tensor, element-wise maximum ofx1 andx2.
mean functionkeras.ops.mean(x,axis=None,keepdims=False)Compute the arithmetic mean along the specified axes.
Arguments
True, the axes which are reduced are left in the result as dimensions with size one.Returns
Output tensor containing the mean values.
median functionkeras.ops.median(x,axis=None,keepdims=False)Compute the median along the specified axis.
Arguments
axis=None which is to compute the median(s) along a flattened version of the array.True, the axes which are reduce are left in the result as dimensions with size one.Returns
The output tensor.
meshgrid functionkeras.ops.meshgrid(*x,indexing="xy")Creates grids of coordinates from coordinate vectors.
GivenN 1-D tensorsT0, T1, ..., TN-1 as inputs with correspondinglengthsS0, S1, ..., SN-1, this creates anN N-dimensional tensorsG0, G1, ..., GN-1 each with shape(S0, ..., SN-1) where the outputGi is constructed by expandingTi to the result shape.
Arguments
"xy" or"ij". "xy" is cartesian;"ij" is matrix indexing of output. Defaults to"xy".Returns
Sequence of N tensors.
Example
>>>fromkeras.srcimportops>>>x=ops.array([1,2,3])>>>y=ops.array([4,5,6])>>>grid_x,grid_y=ops.meshgrid(x,y,indexing="ij")>>>grid_xarray([[1,1,1],[2,2,2],[3,3,3]])>>>grid_yarray([[4,5,6],[4,5,6],[4,5,6]])min functionkeras.ops.min(x,axis=None,keepdims=False,initial=None)Return the minimum of a tensor or minimum along an axis.
Arguments
True, the axes which are reduced are left in the result as dimensions with size one. Defaults toFalse.None.Returns
Minimum ofx.
minimum functionkeras.ops.minimum(x1,x2)Element-wise minimum ofx1 andx2.
Arguments
Returns
Output tensor, element-wise minimum ofx1 andx2.
mod functionkeras.ops.mod(x1,x2)Returns the element-wise remainder of division.
Arguments
Returns
Output tensor, element-wise remainder of division.
moveaxis functionkeras.ops.moveaxis(x,source,destination)Move axes of a tensor to new positions.
Other axes remain in their original order.
Arguments
Returns
Tensor with moved axes.
multiply functionkeras.ops.multiply(x1,x2)Multiply arguments element-wise.
Arguments
Returns
Output tensor, element-wise product ofx1 andx2.
nan_to_num functionkeras.ops.nan_to_num(x,nan=0.0,posinf=None,neginf=None)Replace NaN with zero and infinity with large finite numbers.
Arguments
NaN entries with.Returns
x, with non-finite values replaced.
ndim functionkeras.ops.ndim(x)Return the number of dimensions of a tensor.
Arguments
Returns
The number of dimensions inx.
negative functionkeras.ops.negative(x)Numerical negative, element-wise.
Arguments
Returns
Output tensor,y = -x.
nonzero functionkeras.ops.nonzero(x)Return the indices of the elements that are non-zero.
Arguments
Returns
Indices of elements that are non-zero.
norm functionkeras.ops.norm(x,ord=None,axis=None,keepdims=False)Matrix or vector norm.
This function is able to return one of eight different matrix norms, or oneof an infinite number of vector norms (described below), depending on thevalue of theord parameter.
Arguments
None.axis is an integer, it specifies the axis ofx along which to compute the vector norms. Ifaxis is a 2-tuple, it specifies the axes that hold 2-D matrices, and the matrix norms of these matrices are computed.True, the axes which are reduced are left in the result as dimensions with size one.Note: For values oford < 1, the result is, strictly speaking, not a mathematical 'norm', but it may still be useful for various numerical purposes. The following norms can be calculated: - For matrices: -ord=None: Frobenius norm -ord="fro": Frobenius norm -ord="nuc": nuclear norm -ord=np.inf:max(sum(abs(x), axis=1)) -ord=-np.inf:min(sum(abs(x), axis=1)) -ord=0: not supported -ord=1:max(sum(abs(x), axis=0)) -ord=-1:min(sum(abs(x), axis=0)) -ord=2: 2-norm (largest sing. value) -ord=-2: smallest singular value - other: not supported - For vectors: -ord=None: 2-norm -ord="fro": not supported -ord="nuc": not supported -ord=np.inf:max(abs(x)) -ord=-np.inf:min(abs(x)) -ord=0:sum(x != 0) -ord=1: as below -ord=-1: as below -ord=2: as below -ord=-2: as below - other:sum(abs(x)**ord)**(1./ord)
Returns
Norm of the matrix or vector(s).
Example
>>>x=keras.ops.reshape(keras.ops.arange(9,dtype="float32")-4,(3,3))>>>keras.ops.linalg.norm(x)7.7459664not_equal functionkeras.ops.not_equal(x1,x2)Return(x1 != x2) element-wise.
Arguments
Returns
Output tensor, element-wise comparison ofx1 andx2.
ones functionkeras.ops.ones(shape,dtype=None)Return a new tensor of given shape and type, filled with ones.
Arguments
Returns
Tensor of ones with the given shape and dtype.
ones_like functionkeras.ops.ones_like(x,dtype=None)Return a tensor of ones with the same shape and type ofx.
Arguments
Returns
A tensor of ones with the same shape and type asx.
outer functionkeras.ops.outer(x1,x2)Compute the outer product of two vectors.
Given two vectorsx1 andx2, the outer product is:
out[i, j] = x1[i] * x2[j]Arguments
Returns
Outer product ofx1 andx2.
pad functionkeras.ops.pad(x,pad_width,mode="constant",constant_values=None)Pad a tensor.
Arguments
((before_1, after_1), ...(before_N, after_N)) unique pad widths for each axis.((before, after),) yields same before and after pad for each axis.(pad,) orint is a shortcut forbefore = after = pad width for all axes."constant","edge","linear_ramp","maximum","mean","median","minimum","reflect","symmetric","wrap","empty","circular". Defaults to"constant".mode == "constant". Defaults to0. AValueError is raised if not None andmode != "constant".Note: Torch backend only supports modes"constant","reflect","symmetric" and"circular". Only Torch backend supports"circular" mode.
Note: Tensorflow backend only supports modes"constant","reflect" and"symmetric".
Returns
Padded tensor.
power functionkeras.ops.power(x1,x2)First tensor elements raised to powers from second tensor, element-wise.
Arguments
Returns
Output tensor, the bases inx1 raised to the exponents inx2.
prod functionkeras.ops.prod(x,axis=None,keepdims=False,dtype=None)Return the product of tensor elements over a given axis.
Arguments
axis=None, will compute the product of all elements in the input tensor.True, the axes which are reduce are left in the result as dimensions with size one.Returns
Product of elements ofx over the given axis or axes.
quantile functionkeras.ops.quantile(x,q,axis=None,method="linear",keepdims=False)Compute the q-th quantile(s) of the data along the specified axis.
Arguments
axis=None which is to compute the quantile(s) along a flattened version of the array."linear","lower","higher","midpoint", and"nearest". Defaults to"linear". If the desired quantile lies between two data pointsi < j:"linear":i + (j - i) * fraction, where fraction is the fractional part of the index surrounded byi andj."lower":i."higher":j."midpoint":(i + j) / 2"nearest":i orj, whichever is nearest.True, the axes which are reduce are left in the result as dimensions with size one.Returns
The quantile(s). Ifq is a single probability andaxis=None, thenthe result is a scalar. If multiple probabilities levels are given,first axis of the result corresponds to the quantiles. The other axesare the axes that remain after the reduction ofx.
ravel functionkeras.ops.ravel(x)Return a contiguous flattened tensor.
A 1-D tensor, containing the elements of the input, is returned.
Arguments
Returns
Output tensor.
real functionkeras.ops.real(x)Return the real part of the complex argument.
Arguments
Returns
The real component of the complex argument.
reciprocal functionkeras.ops.reciprocal(x)Return the reciprocal of the argument, element-wise.
Calculates1/x.
Arguments
Returns
Output tensor, element-wise reciprocal ofx.
repeat functionkeras.ops.repeat(x,repeats,axis=None)Repeat each element of a tensor after themselves.
Arguments
Returns
Output tensor.
reshape functionkeras.ops.reshape(x,newshape)Gives a new shape to a tensor without changing its data.
Arguments
Returns
The reshaped tensor.
right_shift functionkeras.ops.right_shift(x,y)Shift the bits of an integer to the right.
Bits are shifted to the righty. Because the internal representation ofnumbers is in binary format, this operation is equivalent to dividingx by2**y.
Arguments
Returns
Result tensor.
roll functionkeras.ops.roll(x,shift,axis=None)Roll tensor elements along a given axis.
Elements that roll beyond the last position are re-introduced at the first.
Arguments
Returns
Output tensor.
rot90 functionkeras.ops.rot90(array,k=1,axes=(0,1))Rotate an array by 90 degrees in the plane specified by axes.
This function rotates an array counterclockwiseby 90 degreesk times in the plane specified byaxes.Supports arrays of two or more dimensions.
Arguments
(0, 1)).Returns
Rotated array.
Examples
>>>importnumpyasnp>>>fromkerasimportops>>>m=np.array([[1,2],[3,4]])>>>rotated=ops.rot90(m)>>>rotatedarray([[2,4],[1,3]])>>>m=np.arange(8).reshape((2,2,2))>>>rotated=ops.rot90(m,k=1,axes=(1,2))>>>rotatedarray([[[1,3],[0,2]],[[5,7],[4,6]]])round functionkeras.ops.round(x,decimals=0)Evenly round to the given number of decimals.
Arguments
0.Returns
Output tensor.
searchsorted functionkeras.ops.searchsorted(sorted_sequence,values,side="left")Perform a binary search, returning indices for insertion ofvaluesintosorted_sequence that maintain the sorting order.
Arguments
Returns
Tensor of insertion indices of same shape asvalues.
select functionkeras.ops.select(condlist,choicelist,default=0)Return elements fromchoicelist, based on conditions incondlist.
Arguments
condlist.False.Returns
Tensor where the output at positionm is them-th elementof the tensor inchoicelist where them-th element of thecorresponding tensor incondlist isTrue.
Example
fromkerasimportopsx=ops.arange(6)condlist=[x<3,x>3]choicelist=[x,x**2]ops.select(condlist,choicelist,42)# # Returns tensor([0, 1, 2, 42, 16, 25])sign functionkeras.ops.sign(x)Returns a tensor with the signs of the elements ofx.
Arguments
Returns
Output tensor of same shape asx.
signbit functionkeras.ops.signbit(x)Return the sign bit of the elements ofx.
The output boolean tensor containsTrue where the sign ofx is negative,andFalse otherwise.
Arguments
Returns
Output boolean tensor of same shape asx.
sin functionkeras.ops.sin(x)Trigonometric sine, element-wise.
Arguments
Returns
Output tensor of same shape asx.
sinh functionkeras.ops.sinh(x)Hyperbolic sine, element-wise.
Arguments
Returns
Output tensor of same shape asx.
size functionkeras.ops.size(x)Return the number of elements in a tensor.
Arguments
Returns
Number of elements inx.
slogdet functionkeras.ops.slogdet(x)Compute the sign and natural logarithm of the determinant of a matrix.
Arguments
Returns
A tuple(sign, logabsdet).sign is a number representingthe sign of the determinant. For a real matrix, this is 1, 0, or -1.For a complex matrix, this is a complex number with absolute value 1(i.e., it is on the unit circle), or else 0.logabsdet is the natural log of the absolute value of the determinant.
sort functionkeras.ops.sort(x,axis=-1)Sorts the elements ofx along a given axis in ascending order.
Arguments
None, the tensor is flattened before sorting. Defaults to-1; the last axis.Returns
Sorted tensor.
split functionkeras.ops.split(x,indices_or_sections,axis=0)Split a tensor into chunks.
Arguments
axis. If a 1-D array of sorted integers, the entries indicate indices at which the tensor will be split alongaxis.0.Note: A split does not have to result in equal division when using Torch backend.
Returns
A list of tensors.
sqrt functionkeras.ops.sqrt(x)Return the non-negative square root of a tensor, element-wise.
Arguments
Returns
Output tensor, the non-negative square root ofx.
square functionkeras.ops.square(x)Return the element-wise square of the input.
Arguments
Returns
Output tensor, the square ofx.
squeeze functionkeras.ops.squeeze(x,axis=None)Remove axes of length one fromx.
Arguments
Returns
The input tensor with all or a subset of the dimensions oflength 1 removed.
stack functionkeras.ops.stack(x,axis=0)Join a sequence of tensors along a new axis.
Theaxis parameter specifies the index of the new axis in thedimensions of the result.
Arguments
0.Returns
The stacked tensor.
std functionkeras.ops.std(x,axis=None,keepdims=False)Compute the standard deviation along the specified axis.
Arguments
True, the axes which are reduced are left in the result as dimensions with size one.Returns
Output tensor containing the standard deviation values.
subtract functionkeras.ops.subtract(x1,x2)Subtract arguments element-wise.
Arguments
Returns
Output tensor, element-wise difference ofx1 andx2.
sum functionkeras.ops.sum(x,axis=None,keepdims=False)Sum of a tensor over the given axes.
Arguments
True, the axes which are reduced are left in the result as dimensions with size one.Returns
Output tensor containing the sum.
swapaxes functionkeras.ops.swapaxes(x,axis1,axis2)Interchange two axes of a tensor.
Arguments
Returns
A tensor with the axes swapped.
take functionkeras.ops.take(x,indices,axis=None)Take elements from a tensor along an axis.
Arguments
Returns
The corresponding tensor of values.
take_along_axis functionkeras.ops.take_along_axis(x,indices,axis=None)Select values fromx at the 1-Dindices along the given axis.
Arguments
Returns
The corresponding tensor of values.
tan functionkeras.ops.tan(x)Compute tangent, element-wise.
Arguments
Returns
Output tensor of same shape asx.
tanh functionkeras.ops.tanh(x)Hyperbolic tangent, element-wise.
Arguments
Returns
Output tensor of same shape asx.
tensordot functionkeras.ops.tensordot(x1,x2,axes=2)Compute the tensor dot product along specified axes.
Arguments
x1 and the first N axes ofx2 in order. The sizes of the corresponding axes must match. - Or, a list of axes to be summed over, first sequence applying tox1, second tox2. Both sequences must be of the same length.Returns
The tensor dot product of the inputs.
tile functionkeras.ops.tile(x,repeats)Repeatx the number of times given byrepeats.
Ifrepeats has lengthd, the result will have dimension ofmax(d, x.ndim).
Ifx.ndim < d,x is promoted to be d-dimensional by prependingnew axes.
Ifx.ndim > d,repeats is promoted tox.ndim by prepending 1's to it.
Arguments
x along each axis.Returns
The tiled output tensor.
trace functionkeras.ops.trace(x,offset=0,axis1=0,axis2=1)Return the sum along diagonals of the tensor.
Ifx is 2-D, the sum along its diagonal with the given offset isreturned, i.e., the sum of elementsx[i, i+offset] for alli.
If a has more than two dimensions, then the axes specified byaxis1andaxis2 are used to determine the 2-D sub-arrays whose traces arereturned.
The shape of the resulting tensor is the same as that ofx withaxis1andaxis2 removed.
Arguments
0.0.(first axis).1 (second axis).Returns
Ifx is 2-D, the sum of the diagonal is returned. Ifx haslarger dimensions, then a tensor of sums along diagonals isreturned.
trapezoid functionkeras.ops.trapezoid(y,x=None,dx=1.0,axis=-1)Integrate along the given axis using the composite trapezoidal rule.
Arguments
y. IfNone, spacing is assumed to bedx.x isNone.Returns
The approximate integral ofy along the given axis.
Example
>>>y=keras.ops.convert_to_tensor([[1,2,3],[4,5,6]])>>>keras.ops.trapezoid(y,axis=1)array([4.,10.],dtype=float32)transpose functionkeras.ops.transpose(x,axes=None)Returns a tensor withaxes transposed.
Arguments
x. By default, the order of the axes are reversed.Returns
x with its axes permuted.
tri functionkeras.ops.tri(N,M=None,k=0,dtype=None)Return a tensor with ones at and below a diagonal and zeros elsewhere.
Arguments
k = 0 is the main diagonal, whilek < 0 is below it, andk > 0 is above. The default is 0.Returns
Tensor with its lower triangle filled with ones and zeros elsewhere.T[i, j] == 1 forj <= i + k, 0 otherwise.
tril functionkeras.ops.tril(x,k=0)Return lower triangle of a tensor.
For tensors withndim exceeding 2,tril will apply to thefinal two axes.
Arguments
0. the main diagonal.k < 0 is below it, andk > 0 is above it.Returns
Lower triangle ofx, of same shape and data type asx.
triu functionkeras.ops.triu(x,k=0)Return upper triangle of a tensor.
For tensors withndim exceeding 2,triu will apply to thefinal two axes.
Arguments
0. the main diagonal.k < 0 is below it, andk > 0 is above it.Returns
Upper triangle ofx, of same shape and data type asx.
true_divide functionkeras.ops.true_divide(x1,x2)Alias forkeras.ops.divide.
trunc functionkeras.ops.trunc(x)Return the truncated value of the input, element-wise.
The truncated value of the scalarx is the nearest integeri which iscloser to zero thanx is. In short, the fractional part of the signednumberx is discarded.
Arguments
Returns
The truncated value of each element inx.
Example
>>>x=ops.array([-1.7,-1.5,-0.2,0.2,1.5,1.7,2.0])>>>ops.trunc(x)array([-1.0,-1.0,-0.0,0.0,1.0,1.0,2.0])unravel_index functionkeras.ops.unravel_index(indices,shape)Convert flat indices to coordinate arrays in a given array shape.
Arguments
Returns
Tuple of arrays for each dimension with unraveled indices.
Example
indices = 5shape = (3, 3)unravel_index(indices, shape)(1, 2) # 5 is at row 1, column 2 in a 3x3 array
var functionkeras.ops.var(x,axis=None,keepdims=False)Compute the variance along the specified axes.
Arguments
True, the axes which are reduced are left in the result as dimensions with size one.Returns
Output tensor containing the variance.
vdot functionkeras.ops.vdot(x1,x2)Return the dot product of two vectors.
If the first argument is complex, the complex conjugate of the firstargument is used for the calculation of the dot product.
Multidimensional tensors are flattened before the dot product is taken.
Arguments
Returns
Output tensor.
vectorize functionkeras.ops.vectorize(pyfunc,excluded=None,signature=None)Turn a function into a vectorized function.
Example
defmyfunc(a,b):returna+bvfunc=keras.ops.vectorize(myfunc)y=vfunc([1,2,3,4],2)# Returns Tensor([3, 4, 5, 6])Arguments
pyfunc unmodified."(m,n),(n)->(m)" for vectorized matrix-vector multiplication. If provided,pyfunc will be called with (and expected to return) arrays with shapes given by the size of corresponding core dimensions. By default,pyfunc is assumed to take scalars tensors as input and output.Returns
A new function that appliespyfunc to every elementof its input along axis 0 (the batch axis).
view functionkeras.ops.view(x,dtype=None)Create a new bitwise view of the same data with the specified dtype.
Arguments
Returns
View of a tensor with data type dtype.
Examples
>>>x=keras.ops.array([1,2,3])>>>xarray([1,2,3],dtype=int32)>>>keras.ops.view(x,dtype="float32")array([1.0e-45,3.0e-45,4.0e-45],dtype=float32)vstack functionkeras.ops.vstack(xs)Stack tensors in sequence vertically (row wise).
Arguments
Returns
Tensor formed by stacking the given tensors.
where functionkeras.ops.where(condition,x1=None,x2=None)Return elements chosen fromx1 orx2 depending oncondition.
Arguments
True, yieldx1, otherwise yieldx2.condition isTrue.condition isFalse.Returns
A tensor with elements fromx1 wherecondition isTrue, andelements fromx2 wherecondition isFalse.
zeros functionkeras.ops.zeros(shape,dtype=None)Return a new tensor of given shape and type, filled with zeros.
Arguments
Returns
Tensor of zeros with the given shape and dtype.
zeros_like functionkeras.ops.zeros_like(x,dtype=None)Return a tensor of zeros with the same shape and type asx.
Arguments
Returns
A tensor of zeros with the same shape and type asx.