Documentation
¶
Overview ¶
Package numgo provides n-dimensional array operations, linear algebra, and numerical primitives. It serves as the numpy equivalent for datascience.
Index ¶
- func AllClose(a, b *NDArray, atol, rtol float64) bool
- func Argwhere(a *NDArray) [][]int
- func ArrayEqual(a, b *NDArray) bool
- func ArrayEquiv(a, b *NDArray) bool
- func BroadcastShapes(a, b []int) ([]int, error)
- func Cond(a *NDArray) (float64, error)
- func Det(a *NDArray) (float64, error)
- func MatrixRank(a *NDArray) (int, error)
- func Nonzero(a *NDArray) [][]int
- func Seed(seed int64)
- func Slogdet(a *NDArray) (sign float64, logdet float64, err error)
- func Trace(a *NDArray) (float64, error)
- type NDArray
- func Absolute(a *NDArray) *NDArray
- func Add(a, b *NDArray) *NDArray
- func AddScalar(a *NDArray, s float64) *NDArray
- func All(a *NDArray, axes ...int) *NDArray
- func Any(a *NDArray, axes ...int) *NDArray
- func Append(a, values *NDArray, axis int) (*NDArray, error)
- func Arange(start, stop, step float64) *NDArray
- func Arccos(a *NDArray) *NDArray
- func Arcsin(a *NDArray) *NDArray
- func Arctan(a *NDArray) *NDArray
- func Arctan2(y, x *NDArray) *NDArray
- func ArgMax(a *NDArray, axis int) *NDArray
- func ArgMin(a *NDArray, axis int) *NDArray
- func ArgSort(a *NDArray, axis int) *NDArray
- func Argpartition(a *NDArray, kth int, axis int) *NDArray
- func Around(a *NDArray, decimals int) *NDArray
- func AsStrided(a *NDArray, shape, strides []int) *NDArray
- func Average(a *NDArray, weights *NDArray, axes ...int) *NDArray
- func Bincount(a *NDArray) *NDArray
- func BroadcastTo(a *NDArray, shape []int) (*NDArray, error)
- func Cbrt(a *NDArray) *NDArray
- func Ceil(a *NDArray) *NDArray
- func Cholesky(a *NDArray) (*NDArray, error)
- func Choose(indices *NDArray, choices []*NDArray) (*NDArray, error)
- func Clip(a *NDArray, min, max float64) *NDArray
- func Compress(condition []bool, a *NDArray, axis int) (*NDArray, error)
- func Concatenate(arrays []*NDArray, axis int) (*NDArray, error)
- func Convolve(a, v *NDArray) (*NDArray, error)
- func Corrcoef(x, y *NDArray) (*NDArray, error)
- func Correlate(a, v *NDArray) (*NDArray, error)
- func Cos(a *NDArray) *NDArray
- func Cosh(a *NDArray) *NDArray
- func CountNonzero(a *NDArray, axes ...int) *NDArray
- func Cov(x *NDArray) (*NDArray, error)
- func Cross(a, b *NDArray) (*NDArray, error)
- func Cumprod(a *NDArray, axis int) *NDArray
- func Cumsum(a *NDArray, axis int) *NDArray
- func Delete(a *NDArray, indices []int, axis int) (*NDArray, error)
- func Diag(a *NDArray, k int) *NDArray
- func Diagflat(a *NDArray, k int) *NDArray
- func Diagonal(a *NDArray, offset, axis1, axis2 int) (*NDArray, error)
- func Div(a, b *NDArray) *NDArray
- func DivScalar(a *NDArray, s float64) *NDArray
- func Divmod(x, y *NDArray) (quotient, remainder *NDArray)
- func Dot(a, b *NDArray) (*NDArray, error)
- func Dsplit(a *NDArray, sections int) ([]*NDArray, error)
- func Dstack(arrays []*NDArray) (*NDArray, error)
- func Eig(a *NDArray) (values, vectors *NDArray, err error)
- func Eigh(a *NDArray) (values, vectors *NDArray, err error)
- func Eigvals(a *NDArray) (*NDArray, error)
- func Einsum(notation string, operands ...*NDArray) (*NDArray, error)
- func Empty(shape ...int) *NDArray
- func Equal(a, b *NDArray) *NDArray
- func Exp(a *NDArray) *NDArray
- func Exp2(a *NDArray) *NDArray
- func ExpandDims(a *NDArray, axis int) *NDArray
- func Expm1(a *NDArray) *NDArray
- func Extract(condition, a *NDArray) *NDArray
- func Eye(n int) *NDArray
- func Fabs(a *NDArray) *NDArray
- func Flatnonzero(a *NDArray) *NDArray
- func Flip(a *NDArray, axis int) *NDArray
- func Fliplr(a *NDArray) *NDArray
- func Flipud(a *NDArray) *NDArray
- func Floor(a *NDArray) *NDArray
- func Fmod(x, y *NDArray) *NDArray
- func FromFunction(shape []int, fn func(indices []int) float64) *NDArray
- func FromIter(ch <-chan float64, count int) *NDArray
- func FromSlice(data []float64) *NDArray
- func FromSlice2D(data [][]float64) *NDArray
- func Full(value float64, shape ...int) *NDArray
- func Geomspace(start, stop float64, num int) *NDArray
- func Greater(a, b *NDArray) *NDArray
- func GreaterEqual(a, b *NDArray) *NDArray
- func Heaviside(x, h0 *NDArray) *NDArray
- func Histogram(a *NDArray, bins int) (counts, edges *NDArray)
- func Hsplit(a *NDArray, sections int) ([]*NDArray, error)
- func Hstack(arrays []*NDArray) (*NDArray, error)
- func Identity(n int) *NDArray
- func In1d(a, b *NDArray) *NDArray
- func Inner(a, b *NDArray) (*NDArray, error)
- func Insert(a *NDArray, index int, values *NDArray, axis int) (*NDArray, error)
- func Intersect1D(a, b *NDArray) *NDArray
- func Inv(a *NDArray) (*NDArray, error)
- func Isclose(a, b *NDArray, atol, rtol float64) *NDArray
- func Isfinite(a *NDArray) *NDArray
- func Isinf(a *NDArray) *NDArray
- func Isnan(a *NDArray) *NDArray
- func Isneginf(a *NDArray) *NDArray
- func Isposinf(a *NDArray) *NDArray
- func Less(a, b *NDArray) *NDArray
- func LessEqual(a, b *NDArray) *NDArray
- func Lexsort(keys []*NDArray) *NDArray
- func Linspace(start, stop float64, num int) *NDArray
- func Log(a *NDArray) *NDArray
- func Log1p(a *NDArray) *NDArray
- func Log2(a *NDArray) *NDArray
- func Log10(a *NDArray) *NDArray
- func LogicalAnd(a, b *NDArray) *NDArray
- func LogicalNot(a *NDArray) *NDArray
- func LogicalOr(a, b *NDArray) *NDArray
- func LogicalXor(a, b *NDArray) *NDArray
- func Logspace(start, stop float64, num int) *NDArray
- func Lstsq(a, b *NDArray) (*NDArray, error)
- func Matmul(a, b *NDArray) (*NDArray, error)
- func MatrixPower(a *NDArray, n int) (*NDArray, error)
- func Max(a *NDArray, axes ...int) *NDArray
- func Mean(a *NDArray, axes ...int) *NDArray
- func Median(a *NDArray, axes ...int) *NDArray
- func Meshgrid(xi ...*NDArray) []*NDArray
- func Min(a *NDArray, axes ...int) *NDArray
- func Modf(x *NDArray) (frac, integer *NDArray)
- func Moveaxis(a *NDArray, source, destination int) *NDArray
- func Mul(a, b *NDArray) *NDArray
- func MulScalar(a *NDArray, s float64) *NDArray
- func Nanmax(a *NDArray, axes ...int) *NDArray
- func Nanmean(a *NDArray, axes ...int) *NDArray
- func Nanmin(a *NDArray, axes ...int) *NDArray
- func Nanprod(a *NDArray, axes ...int) *NDArray
- func Nanstd(a *NDArray, axes ...int) *NDArray
- func Nansum(a *NDArray, axes ...int) *NDArray
- func Nanvar(a *NDArray, axes ...int) *NDArray
- func NewNDArray(shape []int, data []float64) *NDArray
- func Norm(a *NDArray, ord int, axis int) (*NDArray, error)
- func NotEqual(a, b *NDArray) *NDArray
- func Ones(shape ...int) *NDArray
- func Outer(a, b *NDArray) *NDArray
- func Partition(a *NDArray, kth int, axis int) *NDArray
- func Percentile(a *NDArray, q float64, axes ...int) *NDArray
- func Pinv(a *NDArray) (*NDArray, error)
- func Power(base, exp *NDArray) *NDArray
- func Prod(a *NDArray, axes ...int) *NDArray
- func QR(a *NDArray) (q, r *NDArray, err error)
- func Quantile(a *NDArray, q float64, axes ...int) *NDArray
- func Ravel(a *NDArray) *NDArray
- func Remainder(x, y *NDArray) *NDArray
- func Repeat(a *NDArray, repeats int, axis int) *NDArray
- func Rint(a *NDArray) *NDArray
- func Roll(a *NDArray, shift int, axis int) *NDArray
- func Rollaxis(a *NDArray, axis, start int) *NDArray
- func Rot90(a *NDArray, k int) *NDArray
- func SVD(a *NDArray) (u, s, vt *NDArray, err error)
- func SearchSorted(sorted, values *NDArray) *NDArray
- func Select(conditions []*NDArray, choices []*NDArray, defaultVal float64) (*NDArray, error)
- func SetDiff1D(a, b *NDArray) *NDArray
- func Setxor1d(a, b *NDArray) *NDArray
- func Sign(a *NDArray) *NDArray
- func Sin(a *NDArray) *NDArray
- func Sinh(a *NDArray) *NDArray
- func Solve(a, b *NDArray) (*NDArray, error)
- func Sort(a *NDArray, axis int) *NDArray
- func Split(a *NDArray, sections int, axis int) ([]*NDArray, error)
- func Sqrt(a *NDArray) *NDArray
- func Square(a *NDArray) *NDArray
- func Squeeze(a *NDArray) *NDArray
- func Stack(arrays []*NDArray, axis int) (*NDArray, error)
- func Std(a *NDArray, axes ...int) *NDArray
- func Sub(a, b *NDArray) *NDArray
- func SubScalar(a *NDArray, s float64) *NDArray
- func Sum(a *NDArray, axes ...int) *NDArray
- func Swapaxes(a *NDArray, axis1, axis2 int) *NDArray
- func Take(a *NDArray, indices []int, axis int) (*NDArray, error)
- func TakeAlongAxis(a, indices *NDArray, axis int) (*NDArray, error)
- func Tan(a *NDArray) *NDArray
- func Tanh(a *NDArray) *NDArray
- func Tensordot(a, b *NDArray, axes int) (*NDArray, error)
- func Tile(a *NDArray, reps []int) *NDArray
- func Tri(n, m, k int) *NDArray
- func Tril(a *NDArray, k int) *NDArray
- func Triu(a *NDArray, k int) *NDArray
- func Union1D(a, b *NDArray) *NDArray
- func Unique(a *NDArray) *NDArray
- func Vander(x *NDArray, n int) *NDArray
- func Var(a *NDArray, axes ...int) *NDArray
- func Vsplit(a *NDArray, sections int) ([]*NDArray, error)
- func Vstack(arrays []*NDArray) (*NDArray, error)
- func Where(condition, x, y *NDArray) *NDArray
- func Zeros(shape ...int) *NDArray
- func (a *NDArray) Copy() *NDArray
- func (a *NDArray) Data() []float64
- func (a *NDArray) Flatten() *NDArray
- func (a *NDArray) Get(indices ...int) float64
- func (a *NDArray) Ndim() int
- func (a *NDArray) Reshape(shape ...int) *NDArray
- func (a *NDArray) Set(value float64, indices ...int)
- func (a *NDArray) Shape() []int
- func (a *NDArray) Size() int
- func (a *NDArray) String() string
- func (a *NDArray) T() *NDArray
- type RNG
- func (r *RNG) Beta(a, b float64, shape ...int) *NDArray
- func (r *RNG) BinomialSample(n int, p float64, shape ...int) *NDArray
- func (r *RNG) Chisquare(df float64, shape ...int) *NDArray
- func (r *RNG) Choice(n int, size int, replace bool) []int
- func (r *RNG) Dirichlet(alpha []float64) []float64
- func (r *RNG) Exponential(scale float64, shape ...int) *NDArray
- func (r *RNG) Gamma(shapep, scale float64, shapeArr ...int) *NDArray
- func (r *RNG) Multinomial(n int, pvals []float64) []int
- func (r *RNG) Normal(mean, std float64, shape ...int) *NDArray
- func (r *RNG) Permutation(n int) *NDArray
- func (r *RNG) Poisson(lam float64, shape ...int) *NDArray
- func (r *RNG) Rand(shape ...int) *NDArray
- func (r *RNG) RandInt(low, high int, shape ...int) *NDArray
- func (r *RNG) Randn(shape ...int) *NDArray
- func (r *RNG) Random(shape ...int) *NDArray
- func (r *RNG) Shuffle(a *NDArray)
- func (r *RNG) StandardNormal(shape ...int) *NDArray
- func (r *RNG) StandardT(df float64, shape ...int) *NDArray
- func (r *RNG) Uniform(low, high float64, shape ...int) *NDArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllClose ¶
AllClose returns true if two arrays have the same shape and all corresponding elements satisfy |a-b| <= atol + rtol*|b|.
func ArrayEqual ¶
ArrayEqual returns true if a and b have the same shape and all elements are equal.
func ArrayEquiv ¶
ArrayEquiv returns true if a and b are equal after broadcasting to a common shape.
func BroadcastShapes ¶
BroadcastShapes computes the result shape from two input shapes using numpy-style broadcasting rules:
- If arrays differ in number of dimensions, pad the shorter shape with 1s on the left.
- Dimensions with size 1 are stretched to match the other array's size.
- If sizes differ and neither is 1, an error is returned.
func Cond ¶
Cond computes the condition number of a matrix (ratio of largest to smallest singular value).
func Det ¶
Det computes the determinant of a square matrix via LU decomposition (Gaussian elimination).
func MatrixRank ¶
MatrixRank computes the rank of a matrix by counting non-negligible singular values.
func Nonzero ¶
Nonzero returns the indices of all nonzero elements in a. The result is a slice of coordinate tuples, where each tuple has length equal to a.Ndim().
func Seed ¶
func Seed(seed int64)
Seed sets the seed for the package-level default RNG. Safe for concurrent use.
Types ¶
type NDArray ¶
type NDArray struct {
// contains filtered or unexported fields
}
NDArray is a multidimensional array backed by a flat []float64 slice.
func Add ¶
Add returns the element-wise sum of two arrays. Arrays with compatible shapes are broadcast to a common shape before the operation.
func All ¶
All returns 1.0 if all elements along the given axes are nonzero, 0.0 otherwise. If no axes are given, checks all elements.
func Any ¶
Any returns 1.0 if any element along the given axes is nonzero, 0.0 otherwise. If no axes are given, checks all elements.
func Arange ¶
Arange returns a 1D array of evenly spaced values in [start, stop) with the given step.
func ArgMax ¶
ArgMax returns the index of the maximum value along the given axis. Only a single axis is supported. Returns an NDArray of float64 indices.
func ArgMin ¶
ArgMin returns the index of the minimum value along the given axis. Only a single axis is supported. Returns an NDArray of float64 indices.
func ArgSort ¶
ArgSort returns a new NDArray containing the indices that would sort the input array along the given axis. The result has the same shape as the input, with float64 index values.
func Argpartition ¶
Argpartition returns the indices that would partition the array.
func AsStrided ¶
AsStrided creates a view of the array with the given shape and strides. This is an unsafe operation: the returned array shares the same underlying data. Out-of-bounds strides can cause reads beyond the original data.
func Average ¶
Average computes the weighted average along the given axes. If weights is nil, all weights are equal (equivalent to Mean). When axes are specified, weights must have length equal to the axis size.
func Bincount ¶
Bincount counts the number of occurrences of each non-negative integer value. Values are truncated to integers. The result length is max(a)+1.
func BroadcastTo ¶
BroadcastTo broadcasts an NDArray to the given target shape, returning a new NDArray with data repeated as needed. The source array must be broadcast-compatible with the target shape (each source dimension must be 1 or equal to the target dimension).
func Cholesky ¶
Cholesky computes the Cholesky decomposition of a symmetric positive-definite matrix. Returns the lower-triangular matrix L such that A = L * L^T.
func Choose ¶
Choose selects elements from choices based on indices. indices is a 1D array of ints selecting which choice array to pick from. All choices must have the same shape as indices.
func Compress ¶
Compress selects elements from a along the given axis where condition is true. If axis < 0, operates on the flattened array.
func Concatenate ¶
Concatenate joins a sequence of arrays along an existing axis.
func Convolve ¶
Convolve computes the discrete linear convolution of two 1-D arrays (full mode). The result has length len(a) + len(v) - 1.
func Corrcoef ¶
Corrcoef returns the Pearson correlation coefficient matrix for x and y. x and y must be 1-D arrays of the same length. Returns a 2x2 correlation matrix.
func Correlate ¶
Correlate computes the cross-correlation of two 1-D arrays (full mode). The result has length len(a) + len(v) - 1.
func CountNonzero ¶
CountNonzero counts the number of nonzero elements along the given axes. If no axes are given, counts all nonzero elements.
func Cov ¶
Cov returns the covariance matrix for a 2-D array where each row is a variable and each column is an observation. For a 1-D array, returns a 1x1 matrix.
func Diag ¶
Diag extracts or constructs a diagonal.
- If a is 1D, returns a 2D matrix with a on the k-th diagonal.
- If a is 2D, extracts the k-th diagonal as a 1D array.
func Diagonal ¶
Diagonal extracts the diagonal from a 2D array. offset > 0 selects superdiagonals, offset < 0 selects subdiagonals. axis1 and axis2 specify the 2D sub-array to extract from (for higher dims).
func Div ¶
Div returns the element-wise quotient of two arrays. Arrays with compatible shapes are broadcast to a common shape before the operation.
func Divmod ¶
Divmod returns element-wise quotient and remainder of x/y with broadcasting. Quotient is floor(x/y), remainder is x - quotient*y.
func Dot ¶
Dot computes the dot product of two arrays.
- 1D-1D: inner product (scalar result wrapped in 0-D array)
- 2D-2D: matrix multiplication
- 2D-1D: matrix-vector product
func Eig ¶
Eig computes the eigenvalues and right eigenvectors of a square matrix using the QR algorithm. Only supports real eigenvalues.
func Eigh ¶
Eigh computes eigenvalues and eigenvectors of a symmetric matrix. Uses the same QR algorithm but assumes symmetry for better convergence.
func Einsum ¶
Einsum performs Einstein summation on the given operands according to the notation string. It supports numpy-style einsum notation such as:
- "ij,jk->ik" (matrix multiply)
- "ii->" (trace)
- "ij->" (sum all elements)
- "ij->i" (row sums)
- "ij->j" (column sums)
- "i,j->ij" (outer product)
- "bij,bjk->bik" (batch matrix multiply)
If no "->" is given, implicit mode outputs the sorted labels that appear exactly once across all inputs.
func Empty ¶
Empty returns a zero-initialized NDArray of the given shape. In Go, float64 slices are zero-initialized, so this is identical to Zeros.
func ExpandDims ¶
ExpandDims inserts a new axis of size 1 at the given position.
func Extract ¶
Extract returns a 1-D array of elements from a where the corresponding element in condition is nonzero. Both arrays are treated as flat.
func Fabs ¶
Fabs returns the element-wise absolute value of the array (same as Absolute for float64).
func Flatnonzero ¶
Flatnonzero returns the flat indices of nonzero elements.
func FromFunction ¶
FromFunction constructs an NDArray by calling fn for each set of indices.
func FromSlice2D ¶
FromSlice2D creates a 2-D NDArray from a slice of slices. All rows must have the same length.
func Geomspace ¶
Geomspace returns num values spaced evenly on a log scale (geometric progression) from start to stop. Both start and stop must be positive.
func GreaterEqual ¶
GreaterEqual returns 1.0 where a >= b, 0.0 otherwise (element-wise with broadcasting).
func Heaviside ¶
Heaviside computes the Heaviside step function element-wise with broadcasting. Returns 0 where x < 0, h0 where x == 0, and 1 where x > 0.
func Histogram ¶
Histogram computes a histogram of a flat array. Returns counts (length bins) and edges (length bins+1).
func Hsplit ¶
Hsplit splits an array horizontally. For 1-D, splits along axis 0. For 2D+, splits along axis 1.
func Hstack ¶
Hstack stacks arrays horizontally. For 1-D arrays, concatenate. For 2D+, concatenate along axis 1.
func In1d ¶
In1d returns a 1-D NDArray with 1.0 where the corresponding element of a is found in b, and 0.0 otherwise. Both inputs are treated as flat.
func Inner ¶
Inner computes the inner product of two arrays. For 1D arrays, this is the dot product. For higher dimensions, it sums over the last axis of a and the second-to-last of b.
func Intersect1D ¶
Intersect1D returns a sorted 1D NDArray of values common to both a and b. Both inputs are treated as flattened 1D arrays.
func Isclose ¶
Isclose returns 1.0 where |a-b| <= atol + rtol*|b|, 0.0 otherwise (element-wise with broadcasting).
func LessEqual ¶
LessEqual returns 1.0 where a <= b, 0.0 otherwise (element-wise with broadcasting).
func Lexsort ¶
Lexsort performs an indirect stable sort using a sequence of keys. The last key is the primary sort key, the second-to-last is secondary, etc. All keys must be 1-D arrays of the same length. Returns an NDArray of indices that sorts the data.
func LogicalAnd ¶
LogicalAnd returns element-wise logical AND. Nonzero values are treated as true.
func LogicalNot ¶
LogicalNot returns element-wise logical NOT. Nonzero values become 0.0, zero becomes 1.0.
func LogicalXor ¶
LogicalXor returns element-wise logical XOR. Nonzero values are treated as true.
func Lstsq ¶
Lstsq finds the least squares solution to Ax = b via the normal equations (A^T A) x = A^T b.
func MatrixPower ¶
MatrixPower computes A^n for a square matrix via repeated multiplication. n=0 returns identity, negative n uses the inverse.
func Mean ¶
Mean reduces the array by computing the arithmetic mean along the given axes. If no axes are given, it returns the global mean.
func Meshgrid ¶
Meshgrid returns coordinate matrices from coordinate vectors. Given N 1D arrays, returns N NDArrays each with N dimensions.
func Min ¶
Min reduces the array by taking the minimum along the given axes. If no axes are given, it returns the global minimum as a scalar (1-D, length-1) array.
func Modf ¶
Modf returns the fractional and integer parts of each element. Both returned arrays have the same shape as the input.
func Mul ¶
Mul returns the element-wise product of two arrays. Arrays with compatible shapes are broadcast to a common shape before the operation.
func NewNDArray ¶
NewNDArray creates an NDArray with the given shape and optional data. If data is nil, the array is zero-initialized. If data is provided, its length must equal the product of shape dimensions.
func Norm ¶
Norm computes a vector or matrix norm.
ord=1: sum of absolute values (or max column sum for matrices) ord=2: Euclidean norm (or spectral norm for matrices) ord=-1: for vectors, min of absolute values
axis=-1 means compute over the flattened array.
func Partition ¶
Partition rearranges elements along the given axis such that the element at position kth is in its sorted position, all smaller elements are before it, and all larger elements are after it (using introselect/quickselect).
func Percentile ¶
Percentile returns the q-th percentile of the array along the given axes. q must be in [0, 100]. Uses linear interpolation.
func QR ¶
QR computes the QR factorization of a 2D matrix using the Gram-Schmidt process. Returns Q (orthogonal) and R (upper triangular) such that A = Q * R.
func Quantile ¶
Quantile returns the q-th quantile of the array along the given axes. q must be in [0, 1]. Uses linear interpolation.
func Remainder ¶
Remainder returns the element-wise IEEE 754 remainder (math.Remainder) with broadcasting.
func Roll ¶
Roll performs a circular shift of elements along the given axis. If axis is -1, the array is flattened, rolled, then reshaped.
func Rot90 ¶
Rot90 rotates the array 90 degrees counter-clockwise k times in the plane defined by axes 0 and 1.
func SVD ¶
SVD computes the singular value decomposition A = U * diag(S) * Vt. Uses eigendecomposition of A^T A and A A^T.
func SearchSorted ¶
SearchSorted performs a binary search on a sorted 1D array, returning the indices at which the given values should be inserted to maintain sort order. The sorted array must be 1D. The result has the same shape as values.
func Select ¶
Select returns elements from choices based on conditions. The first true condition selects the corresponding choice. If no condition is true, defaultVal is used.
func SetDiff1D ¶
SetDiff1D returns a sorted 1D NDArray of values in a that are not in b. Both inputs are treated as flattened 1D arrays.
func Setxor1d ¶
Setxor1d returns a sorted 1D NDArray of values that are in exactly one of a or b (symmetric difference). Both inputs are treated as flat.
func Sign ¶
Sign returns the element-wise sign of the array: -1 for negative, 0 for zero, 1 for positive.
func Solve ¶
Solve solves the linear system Ax = b via Gaussian elimination with partial pivoting. a must be a square 2D matrix, b must be a 1D or 2D array.
For large systems (n >= Level2Threshold), uses LU factorization with BLAS triangular solve (Dtrsv) for better cache performance.
func Sort ¶
Sort returns a new NDArray with elements sorted along the given axis. For a 1D array, axis must be 0. For an ND array, each 1D slice along the specified axis is sorted independently.
func Std ¶
Std computes the population standard deviation along the given axes. If no axes are given, it returns the global standard deviation.
func Sub ¶
Sub returns the element-wise difference of two arrays. Arrays with compatible shapes are broadcast to a common shape before the operation.
func Sum ¶
Sum reduces the array by summing along the given axes. If no axes are given, it sums over all elements and returns a scalar (1-D, length-1) array.
func Take ¶
Take returns elements from a along the given axis at the specified indices. If axis < 0, operates on the flattened array.
func TakeAlongAxis ¶
TakeAlongAxis gathers elements from a along the given axis using indices array. indices must have the same number of dimensions as a.
func Tensordot ¶
Tensordot computes the tensor contraction of a and b over the last `axes` axes of a and the first `axes` axes of b.
func Tril ¶
Tril returns the lower triangle of a 2D array. Elements above the k-th diagonal are zeroed.
func Triu ¶
Triu returns the upper triangle of a 2D array. Elements below the k-th diagonal are zeroed.
func Union1D ¶
Union1D returns a sorted 1D NDArray of the unique values from both a and b. Both inputs are treated as flattened 1D arrays.
func Vander ¶
Vander returns the Vandermonde matrix of a 1D input. Column j of the output is x^(n-1-j). If n <= 0, n defaults to len(x).
func Var ¶
Var computes the population variance along the given axes. If no axes are given, it returns the global variance.
func Where ¶
Where performs element-wise selection: for each element, if condition is nonzero (true), pick from x; otherwise pick from y. condition, x, and y must be broadcast-compatible.
func (*NDArray) Reshape ¶
Reshape returns a new NDArray with the same data but a different shape. The total number of elements must remain the same.
type RNG ¶
type RNG struct {
// contains filtered or unexported fields
}
RNG wraps a seeded random source for reproducible random number generation.
func (*RNG) Beta ¶
Beta returns samples from a Beta(a, b) distribution using the Gamma distribution.
func (*RNG) BinomialSample ¶
BinomialSample returns samples from a binomial distribution with parameters n and p.
func (*RNG) Chisquare ¶
Chisquare returns samples from a chi-squared distribution with df degrees of freedom. Chi-squared(df) = Gamma(df/2, 2).
func (*RNG) Choice ¶
Choice returns a slice of random indices in [0, n). If replace is true, indices may repeat; otherwise they are unique and size must be <= n.
func (*RNG) Dirichlet ¶
Dirichlet draws a single sample from the Dirichlet distribution with parameter vector alpha. It returns a probability vector of length len(alpha). The implementation draws independent Gamma(alpha_i, 1) samples and normalizes.
func (*RNG) Exponential ¶
Exponential returns samples from an exponential distribution with the given scale.
func (*RNG) Multinomial ¶
Multinomial draws a single sample from the multinomial distribution: distribute n trials among len(pvals) categories with the given probabilities. Returns a slice of counts (length len(pvals)) summing to n.
func (*RNG) Normal ¶
Normal returns an NDArray of the given shape with values drawn from a normal distribution with the specified mean and standard deviation.
func (*RNG) Permutation ¶
Permutation returns an NDArray containing a random permutation of integers [0, n).
func (*RNG) Poisson ¶
Poisson returns samples from a Poisson distribution with the given rate (lambda). Uses Knuth's algorithm for small lambda, and a rejection method for large lambda.
func (*RNG) Rand ¶
Rand returns an NDArray of the given shape with values drawn uniformly from [0, 1).
func (*RNG) RandInt ¶
RandInt returns an NDArray of the given shape with integer values drawn uniformly from [low, high).
func (*RNG) Randn ¶
Randn returns an NDArray of the given shape with values drawn from the standard normal distribution (mean=0, std=1) using the Box-Muller transform.
func (*RNG) Random ¶
Random returns an NDArray of the given shape with values drawn uniformly from [0, 1). It is an alias for Rand.
func (*RNG) Shuffle ¶
Shuffle performs an in-place Fisher-Yates shuffle on the first axis of the array. For 1-D arrays this shuffles elements; for N-D arrays it shuffles the sub-arrays along axis 0.
func (*RNG) StandardNormal ¶
StandardNormal returns samples from the standard normal distribution (mean=0, std=1). It is an alias for Randn.