MLX provides a comprehensive set of operations for array manipulation, mathematical computations, and linear algebra. Most operations support broadcasting and can be executed on different devices.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ml-explore/mlx/llms.txt
Use this file to discover all available pages before exploring further.
Array Creation
arange
Create a 1D array with evenly spaced values.Start of the range.
End of the range (exclusive).
Spacing between values.
The data type of the output array. If not specified, inferred from the inputs.
The stream on which to schedule the operation.
1D array of evenly spaced values.
linspace
Create a 1D array with a specified number of evenly spaced values.Start of the range.
End of the range (inclusive).
Number of values to generate.
The data type of the output array.
The stream on which to schedule the operation.
1D array of evenly spaced values.
zeros
Create an array filled with zeros.Shape of the array.
The data type of the output array.
The stream on which to schedule the operation.
Array filled with zeros.
ones
Create an array filled with ones.Shape of the array.
The data type of the output array.
The stream on which to schedule the operation.
Array filled with ones.
full
Create an array filled with a specified value.Shape of the array.
The fill value.
The data type of the output array. If not specified, inferred from val.
The stream on which to schedule the operation.
Array filled with the specified value.
eye
Create a 2D identity matrix.Number of rows.
Number of columns. If not specified, defaults to n.
Index of the diagonal. 0 is the main diagonal, positive values are above, negative below.
The data type of the output array.
The stream on which to schedule the operation.
2D array with ones on the specified diagonal.
identity
Create a square identity matrix.Size of the square matrix.
The data type of the output array.
The stream on which to schedule the operation.
Square identity matrix of size n x n.
Shape Manipulation
reshape
Reshape an array without changing its data.Input array.
New shape. One dimension can be -1, which will be inferred.
The stream on which to schedule the operation.
Reshaped array.
flatten
Flatten an array to 1D.Input array.
First axis to flatten.
Last axis to flatten.
The stream on which to schedule the operation.
Flattened array.
squeeze
Remove singleton dimensions.Input array.
Axis or axes to squeeze. If not specified, all singleton dimensions are removed.
The stream on which to schedule the operation.
Squeezed array.
expand_dims
Add singleton dimensions to an array.Input array.
Position(s) where new axis should be added.
The stream on which to schedule the operation.
Array with added dimensions.
transpose
Permute the dimensions of an array.Input array.
Permutation of axes. If not specified, reverses all dimensions.
The stream on which to schedule the operation.
Transposed array.
swapaxes
Swap two axes of an array.Input array.
First axis.
Second axis.
The stream on which to schedule the operation.
Array with swapped axes.
moveaxis
Move an axis to a new position.Input array.
Original position of the axis.
Destination position for the axis.
The stream on which to schedule the operation.
Array with moved axis.
Arithmetic Operations
add
Element-wise addition.First input array.
Second input array.
The stream on which to schedule the operation.
Element-wise sum.
subtract
Element-wise subtraction.First input array.
Second input array.
The stream on which to schedule the operation.
Element-wise difference.
multiply
Element-wise multiplication.First input array.
Second input array.
The stream on which to schedule the operation.
Element-wise product.
divide
Element-wise division.First input array (numerator).
Second input array (denominator).
The stream on which to schedule the operation.
Element-wise quotient.
floor_divide
Element-wise floor division (integer division).First input array.
Second input array.
The stream on which to schedule the operation.
Element-wise floor quotient.
remainder
Element-wise remainder of division.First input array.
Second input array.
The stream on which to schedule the operation.
Element-wise remainder.
power
Element-wise exponentiation.Base array.
Exponent array.
The stream on which to schedule the operation.
Element-wise power.
Mathematical Functions
abs
Element-wise absolute value.Input array.
The stream on which to schedule the operation.
Absolute values.
sqrt
Element-wise square root.Input array.
The stream on which to schedule the operation.
Square roots.
rsqrt
Element-wise reciprocal square root (1/sqrt(x)).Input array.
The stream on which to schedule the operation.
Reciprocal square roots.
exp
Element-wise exponential (e^x).Input array.
The stream on which to schedule the operation.
Exponentials.
log
Element-wise natural logarithm.Input array.
The stream on which to schedule the operation.
Natural logarithms.
log2
Element-wise base-2 logarithm.Input array.
The stream on which to schedule the operation.
Base-2 logarithms.
log10
Element-wise base-10 logarithm.Input array.
The stream on which to schedule the operation.
Base-10 logarithms.
Trigonometric Functions
sin
Element-wise sine.Input array in radians.
The stream on which to schedule the operation.
Sines of input values.
cos
Element-wise cosine.Input array in radians.
The stream on which to schedule the operation.
Cosines of input values.
tan
Element-wise tangent.Input array in radians.
The stream on which to schedule the operation.
Tangents of input values.
Linear Algebra
matmul
Matrix multiplication.First input array.
Second input array.
The stream on which to schedule the operation.
Matrix product of a and b.
outer
Outer product of two vectors.First input vector.
Second input vector.
The stream on which to schedule the operation.
Outer product.
inner
Inner product of two vectors.First input vector.
Second input vector.
The stream on which to schedule the operation.
Inner product.
Comparison Operations
equal
Element-wise equality comparison.First input array.
Second input array.
The stream on which to schedule the operation.
Boolean array of comparison results.
greater
Element-wise greater-than comparison.First input array.
Second input array.
The stream on which to schedule the operation.
Boolean array of comparison results.
less
Element-wise less-than comparison.First input array.
Second input array.
The stream on which to schedule the operation.
Boolean array of comparison results.
allclose
Test if two arrays are element-wise equal within a tolerance.First input array.
Second input array.
Relative tolerance.
Absolute tolerance.
If True, NaNs are considered equal.
The stream on which to schedule the operation.
Boolean scalar indicating if arrays are close.
Concatenation and Stacking
concatenate
Concatenate arrays along an existing axis.List of arrays to concatenate.
Axis along which to concatenate.
The stream on which to schedule the operation.
Concatenated array.
stack
Stack arrays along a new axis.List of arrays to stack.
Axis along which to stack.
The stream on which to schedule the operation.
Stacked array with one additional dimension.
Indexing and Slicing
take
Take elements from an array along an axis.Input array.
Indices of elements to take.
Axis along which to take elements. If not specified, the array is flattened.
The stream on which to schedule the operation.
Array with selected elements.
where
Select elements from x or y depending on condition.Boolean condition array.
Values to select where condition is True.
Values to select where condition is False.
The stream on which to schedule the operation.
Array with elements from x where condition is True, otherwise from y.