Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

NumPy

Migration guide for NumPy.

Common Operations

Description NumPy stdlib
Append a zero-filled array of the same shape along a specified dimension np.concat((x, np.zeros_like(x)), axis=dim) concat([x, zerosLike(x)], {dim: dim})
Broadcast an array to a specified shape np.broadcast_to(x, shape) broadcastArray(x, shape)
Broadcast a scalar to a specified shape np.broadcast_to(np.array(scalar), shape) broadcastScalar(scalar, shape)
Compute the maximum absolute value np.max(np.abs(x)) maxabs(x)
Compute the minimum absolute value np.min(np.abs(x)) minabs(x)
Concatenate a list of arrays along the second-to-last dimension np.concat(arrays, axis=-2) vconcat(arrays)
Concatenate a list of arrays along the last dimension np.concat(arrays, axis=-1) hconcat(arrays)
Concatenate a list of one-dimensional arrays as columns np.column_stack(arrays) colcat(arrays)
Concatenate a list of one-dimensional arrays as rows np.vstack(arrays) rowcat(arrays)
Copy an array np.copy(x) copy(x)
Count the number of falsy values in an array x.size-np.count_nonzero(x) countFalsy(x)
Count the number of truthy values in an array np.count_nonzero(x) countTruthy(x)
Create a sorted copy of an array np.sort(x) toSorted(x)
Create an array containing evenly spaced numbers over a specified interval and having a desired shape np.reshape(np.linspace(start, stop), shape) linspace(shape, start, stop)
Create an array of uniformly distributed pseudorandom numbers np.random.default_rng().uniform(low,high,shape) uniform(shape,low,high)
Filter an array according to a predicate function x[np.vectorize(predicate)(x)] filter(x, predicate)
Find the index of the first element which equals a specified value np.argmax(x == v, axis=dim) indexOf(x, v, {dim: dim})
Find the index of the last element which equals a specified value x.shape[dim]-1-np.argmax(np.flip(x, axis=dim) == v, axis=dim) lastIndexOf(x, v, {dim: dim})
Flatten an array to a desired depth np.reshape(x, newshape) flatten(x, {depth: depth})
Flatten an array starting from a specific dimension np.reshape(x, x.shape[:dim] + (-1,)) flattenFrom(x, dim)
Prepend a specified number of singleton dimensions np.reshape(x, (1,)*n + x.shape) prependSingletonDimensions(x, n)
Prepend a zero-filled array of the same shape along a specified dimension np.concat((np.zeros_like(x), x), axis=dim) concat([zerosLike(x), x], {dim: dim})
Remove singleton dimensions np.squeeze(x) removeSingletonDimensions(x)
Reverse the elements along a dimension np.flip(x, axis=dim) reverseDimension(x, dim)
Rotate an array by 90 degrees in a specified plane np.rot90(x, axes=dims) rot90(x, {dims: dims})
Rotate an array by 180 degrees in a specified plane np.rot90(x, k=2, axes=dims) rot180(x, {dims: dims})
Sort an array in-place x[:] = np.sort(x) sort(x)
Test whether an array contains at least n truthy values np.count_nonzero(x) >= n some(x, n)
Test whether an array contains truthy values np.any(x) any(x)
Test whether an array includes a specific value np.any(x == v) includes(x,v)

Function Reference

{{table}}