arkouda.numpy.pdarraycreation

Functions

arange(…)

Create a pdarray of consecutive integers within the interval [start, stop).

array(…)

Convert a Python, NumPy, or Arkouda array-like into a pdarray or Strings object,

bigint_from_uint_arrays(arrays[, max_bits])

Create a bigint pdarray from an iterable of uint pdarrays.

full(…)

Create a pdarray filled with fill_value.

full_like(→ Union[arkouda.numpy.pdarrayclass.pdarray, ...)

Create a pdarray filled with fill_value of the same size and dtype as an existing

linspace(→ arkouda.numpy.pdarrayclass.pdarray)

Return evenly spaced numbers over a specified interval.

logspace(→ arkouda.numpy.pdarrayclass.pdarray)

Create a pdarray of numbers evenly spaced on a log scale.

ones(…)

Create a pdarray filled with ones.

ones_like(→ arkouda.numpy.pdarrayclass.pdarray)

Create a one-filled pdarray of the same size and dtype as an existing

promote_to_common_dtype(→ Tuple[Any, ...)

Promote a list of pdarrays to a common dtype.

randint(→ arkouda.numpy.pdarrayclass.pdarray)

Generate a pdarray of randomized int, float, or bool values in a

random_strings_lognormal(→ arkouda.numpy.strings.Strings)

Generate random strings with log-normally distributed lengths and

random_strings_uniform(→ arkouda.numpy.strings.Strings)

Generate random strings with lengths uniformly distributed between

scalar_array(→ arkouda.numpy.pdarrayclass.pdarray)

Create a pdarray from a single scalar value.

standard_normal(→ arkouda.numpy.pdarrayclass.pdarray)

Draw real numbers from the standard normal distribution.

uniform(, high, seed, ...)

Generate a pdarray with uniformly distributed random float values

zeros(…)

Create a pdarray filled with zeros.

zeros_like(→ arkouda.numpy.pdarrayclass.pdarray)

Create a zero-filled pdarray of the same size and dtype as an existing

Module Contents

arkouda.numpy.pdarraycreation.arange(__arg1: arkouda.numpy.dtypes.int_scalars, *, dtype: numpy.dtype | type | arkouda.numpy.dtypes.bigint | None = None, max_bits: int | None = None) arkouda.numpy.pdarrayclass.pdarray[source]
arkouda.numpy.pdarraycreation.arange(__arg1: arkouda.numpy.dtypes.int_scalars, __arg2: arkouda.numpy.dtypes.int_scalars, *, dtype: numpy.dtype | type | arkouda.numpy.dtypes.bigint | None = None, max_bits: int | None = None) arkouda.numpy.pdarrayclass.pdarray
arkouda.numpy.pdarraycreation.arange(__arg1: arkouda.numpy.dtypes.int_scalars, __arg2: arkouda.numpy.dtypes.int_scalars, __arg3: arkouda.numpy.dtypes.int_scalars, *, dtype: numpy.dtype | type | arkouda.numpy.dtypes.bigint | None = None, max_bits: int | None = None) arkouda.numpy.pdarrayclass.pdarray

Create a pdarray of consecutive integers within the interval [start, stop).

Called as: arange([start,] stop[, step,] dtype=int64).

If only one arg is given then arg is the stop parameter. If two args are given, then the first arg is start and second is stop. If three args are given, then the first arg is start, second is stop, third is step.

The return value is cast to type dtype

Parameters:
  • start (int_scalars, optional)

  • stop (int_scalars, optional)

  • step (int_scalars, optional) – if one of these three is supplied, it’s used as stop, and start = 0, step = 1 if two of them are supplied, start = start, stop = stop, step = 1 if all three are supplied, start = start, stop = stop, step = step

  • dtype (np.dtype, type, or str) – The target dtype to cast values to

  • max_bits (int) – Specifies the maximum number of bits; only used for bigint pdarrays

Returns:

Integers from start (inclusive) to stop (exclusive) by step

Return type:

pdarray

Raises:
  • ValueError – Raised if none of start, stop, step was supplied

  • TypeError – Raised if start, stop, or step is not an int object

  • ZeroDivisionError – Raised if step == 0

See also

linspace, zeros, ones, randint

Notes

Negative steps result in decreasing values. Currently, only int64 pdarrays can be created with this method. For float64 arrays, use the linspace method.

Examples

>>> import arkouda as ak
>>> ak.arange(0, 5, 1)
array([0 1 2 3 4])
>>> ak.arange(5, 0, -1)
array([5 4 3 2 1])
>>> ak.arange(0, 10, 2)
array([0 2 4 6 8])
>>> ak.arange(-5, -10, -1)
array([-5 -6 -7 -8 -9])
arkouda.numpy.pdarraycreation.array(a: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | Iterable[Any] | numpy.typing.NDArray[Any], dtype: arkouda.numpy._typing._typing._StringDType = ..., *, copy: bool = ..., max_bits: int = ..., unsafe: bool = ..., any_neg: bool | None = ..., num_bits: int | None = ...) arkouda.numpy.strings.Strings[source]
arkouda.numpy.pdarraycreation.array(a: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | Iterable[Any] | numpy.typing.NDArray[Any], dtype: arkouda.numpy._typing._typing._NumericLikeDType = ..., *, copy: bool = ..., max_bits: int = ..., unsafe: bool = ..., any_neg: bool | None = ..., num_bits: int | None = ...) arkouda.numpy.pdarrayclass.pdarray
arkouda.numpy.pdarraycreation.array(a: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | Iterable[Any] | numpy.typing.NDArray[Any], dtype=None, *, copy: bool = ..., max_bits: int = ..., unsafe: bool = ..., any_neg: bool | None = ..., num_bits: int | None = ...) arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings
arkouda.numpy.pdarraycreation.array(a: arkouda.numpy.pdarrayclass.pdarray | List[arkouda.numpy._typing._typing._NumericLikeDType], dtype: arkouda.numpy._typing._typing._StringDType | arkouda.numpy._typing._typing._NumericLikeDType | None = None, copy: bool = False, max_bits: int = -1, *, unsafe: bool = ..., any_neg: bool | None = ..., num_bits: int | None = ...) arkouda.numpy.pdarrayclass.pdarray
arkouda.numpy.pdarraycreation.array(a: arkouda.numpy.strings.Strings | Iterable[arkouda.numpy._typing._typing._StringDType], dtype: arkouda.numpy._typing._typing._StringDType | arkouda.numpy._typing._typing._NumericLikeDType | None = None, copy: bool = False, max_bits: int = -1, *, unsafe: bool = ..., any_neg: bool | None = ..., num_bits: int | None = ...) arkouda.numpy.strings.Strings
arkouda.numpy.pdarraycreation.array(a: arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings | Iterable[Any] | numpy.typing.NDArray[Any], dtype: arkouda.numpy._typing._typing._StringDType | arkouda.numpy._typing._typing._NumericLikeDType | None = None, copy: bool = False, max_bits: int = -1, *, unsafe: bool = ..., any_neg: bool | None = ..., num_bits: int | None = ...) arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings

Convert a Python, NumPy, or Arkouda array-like into a pdarray or Strings object, transferring data to the Arkouda server.

Bigint fast path

When dtype is bigint (or "bigint") and the input is a NumPy dtype=object array, building the bigint representation may require Python-level passes over the data to infer sign and required bit width.

Set unsafe=True to enable optional performance shortcuts for trusted inputs:

  • If both any_neg and num_bits are provided, Arkouda will trust these hints and skip inference passes, proceeding directly to limb extraction.

  • If hints are not provided, Arkouda may still perform a single-pass inference step for dtype=object inputs (implementation-dependent).

Warning

If unsafe=True and the provided hints are incorrect, results may be incorrect.

param a:

The array-like input to convert. Supported types include Arkouda Strings, pdarray, NumPy ndarray, or Python iterables such as list, tuple, range, or deque.

type a:

Union[pdarray, np.ndarray, Iterable, Strings]

param dtype:

The target dtype to cast values to. This may be a NumPy dtype object, a NumPy scalar type (e.g. np.int64), or a string (e.g. ‘int64’, ‘str’).

type dtype:

Union[np.dtype, type, str], optional

param copy:

If True, a deep copy of the array is made. If False, no copy is made if the input is already a pdarray. Note: Arkouda does not currently support views or shallow copies. This differs from NumPy. Also, the default (False) is chosen to reduce performance overhead.

type copy:

bool, default=False

param max_bits:

The maximum number of bits for bigint arrays. Ignored for other dtypes.

type max_bits:

int, optional

param unsafe:

Enable performance-oriented shortcuts for bigint creation from dtype=object arrays. When True, the caller may supply trusted hints (any_neg, num_bits) to skip Python-level full-array scans. If hints are not supplied, Arkouda will still do a single-pass scan (rather than multiple scans) for dtype=object.

WARNING: If unsafe=True and provided hints are wrong, results may be incorrect.

type unsafe:

bool, default=False

param any_neg:

Bigint hint: whether any value is negative. Only used when dtype=bigint and a is numeric/object.

type any_neg:

Optional[bool], default=None

param num_bits:

Bigint hint: required bit-width for values (including sign bit if signed). If provided with unsafe=True, Arkouda can compute number of limbs without scanning.

type num_bits:

Optional[int], default=None

returns:

A pdarray stored on the Arkouda server, or a Strings object.

rtype:

Union[pdarray, Strings]

raises TypeError:
  • If a is not a pdarray, np.ndarray, or Python iterable.

  • If a is of string type and dtype is not ak.str_.

raises RuntimeError:
  • If input size exceeds ak.core.client.maxTransferBytes.

  • If a.dtype is unsupported or incompatible with Arkouda.

  • If a.size * a.itemsize > maxTransferBytes.

raises ValueError:
  • If a’s rank is not supported (see get_array_ranks()).

  • If the server response is malformed or missing required fields.

See also

pdarray.to_ndarray

Convert back from Arkouda to NumPy.

Notes

  • Arkouda does not currently support shallow copies or views; all copies are deep.

  • The number of bytes transferred to the server is limited by ak.core.client.maxTransferBytes. This prevents saturating the network during large transfers. To increase this limit, set ak.core.client.maxTransferBytes to a larger value manually.

  • If the input is a Unicode string array (dtype.kind == ‘U’ or dtype=’str’), this function recursively creates a Strings object from two internal `pdarray`s (one for offsets and one for concatenated string bytes).

Examples

>>> import arkouda as ak
>>> ak.array(np.arange(1, 10))
array([1 2 3 4 5 6 7 8 9])
>>> ak.array(range(1, 10))
array([1 2 3 4 5 6 7 8 9])
>>> strings = ak.array([f'string {i}' for i in range(5)])
>>> type(strings)
<class 'arkouda.numpy.strings.Strings'>
arkouda.numpy.pdarraycreation.bigint_from_uint_arrays(arrays, max_bits=-1)[source]

Create a bigint pdarray from an iterable of uint pdarrays. The first item in arrays will be the highest 64 bits and the last item will be the lowest 64 bits.

Parameters:
  • arrays (Sequence[pdarray]) – An iterable of uint pdarrays used to construct the bigint pdarray. The first item in arrays will be the highest 64 bits and the last item will be the lowest 64 bits.

  • max_bits (int) – Specifies the maximum number of bits; only used for bigint pdarrays

Returns:

bigint pdarray constructed from uint arrays

Return type:

pdarray

Raises:
  • TypeError – Raised if any pdarray in arrays has a dtype other than uint or if the pdarrays are not the same size.

  • RuntimeError – Raised if there is a server-side error thrown

See also

pdarray.bigint_to_uint_arrays

Examples

>>> import arkouda as ak
>>> a = ak.bigint_from_uint_arrays([ak.ones(5, dtype=ak.uint64), ak.arange(5, dtype=ak.uint64)])
>>> a
array([18446744073709551616 18446744073709551617 18446744073709551618
18446744073709551619 18446744073709551620])
>>> a.dtype
dtype(bigint)
>>> all(a[i] == 2**64 + i for i in range(5))
True
arkouda.numpy.pdarraycreation.full(size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | str, fill_value: arkouda.numpy.dtypes.str_scalars, dtype: None = ..., max_bits: int | None = ...) arkouda.numpy.strings.Strings[source]
arkouda.numpy.pdarraycreation.full(size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | str, fill_value: arkouda.numpy.dtypes.numeric_and_bool_scalars, dtype: None = ..., max_bits: int | None = ...) arkouda.numpy.pdarrayclass.pdarray
arkouda.numpy.pdarraycreation.full(size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | str, fill_value: arkouda.numpy.dtypes.numeric_and_bool_scalars | arkouda.numpy.dtypes.str_scalars, dtype: arkouda.numpy._typing._typing.StringDTypeTypes, max_bits: int | None = ...) arkouda.numpy.strings.Strings
arkouda.numpy.pdarraycreation.full(size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | str, fill_value: arkouda.numpy.dtypes.numeric_and_bool_scalars | arkouda.numpy.dtypes.str_scalars, dtype: numpy.dtype[Any] | arkouda.numpy._typing._typing.BuiltinNumericTypes | arkouda.numpy._typing._typing.ArkoudaNumericTypes | arkouda.numpy.dtypes.bigint | type[arkouda.numpy.dtypes.bigint], max_bits: int | None = ...) arkouda.numpy.pdarrayclass.pdarray
arkouda.numpy.pdarraycreation.full(size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | str, fill_value: arkouda.numpy.dtypes.numeric_and_bool_scalars | arkouda.numpy.dtypes.str_scalars, dtype: Literal['bigint', 'float64', 'int8', 'int64', 'uint8', 'uint64', 'bool', 'bool_'], max_bits: int | None = ...) arkouda.numpy.pdarrayclass.pdarray

Create a pdarray filled with fill_value.

Parameters:
  • size (int_scalars or tuple of int_scalars) – Size or shape of the array

  • fill_value (numeric_scalars, bool_scalars or str_scalars) – Value with which the array will be filled

  • dtype (all_scalars) – Resulting array type. If None, it will be inferred from fill_value

  • max_bits (int) – Specifies the maximum number of bits; only used for bigint pdarrays

Returns:

array of the requested size and dtype filled with fill_value

Return type:

pdarray or Strings

Raises:
  • TypeError – Raised if the supplied dtype is not supported

  • RuntimeError – Raised if the size parameter is neither an int nor a str that is parseable to an int.

  • ValueError – Raised if the rank of the given shape is not in get_array_ranks() or is empty Raised if a multi-dim Strings array was requested Raised if max_bits is not NONE and ndim does not equal 1

See also

zeros, ones

Examples

>>> import arkouda as ak
>>> ak.full(5, 7, dtype=ak.int64)
array([7 7 7 7 7])
>>> ak.full(5, 9, dtype=ak.float64)
array([9.00000000000000000 9.00000000000000000 9.00000000000000000
       9.00000000000000000 9.00000000000000000])
>>> ak.full(5, 5, dtype=ak.bool_)
array([True True True True True])
arkouda.numpy.pdarraycreation.full_like(pda: arkouda.numpy.pdarrayclass.pdarray, fill_value: arkouda.numpy.dtypes.numeric_scalars) arkouda.numpy.pdarrayclass.pdarray | arkouda.numpy.strings.Strings[source]

Create a pdarray filled with fill_value of the same size and dtype as an existing pdarray.

Parameters:
  • pda (pdarray) – Array to use for shape and dtype

  • fill_value (int_scalars) – Value with which the array will be filled

Returns:

Equivalent to ak.full(pda.shape, fill_value, pda.dtype)

Return type:

pdarray

Raises:

TypeError – Raised if the pda parameter is not a pdarray.

See also

ones_like, zeros_like

Notes

Logic for generating the pdarray is delegated to the ak.full method. Accordingly, the supported dtypes match are defined by the ak.full method.

Examples

>>> import arkouda as ak
>>> ak.full_like(ak.full(5,7,dtype=ak.int64),6)
array([6 6 6 6 6])
>>> ak.full_like(ak.full(7,9,dtype=ak.float64),10)
array([10.00000000000000000 10.00000000000000000 10.00000000000000000
       10.00000000000000000 10.00000000000000000 10.00000000000000000 10.00000000000000000])
>>> ak.full_like(ak.full(5,True,dtype=ak.bool_),False)
array([False False False False False])
arkouda.numpy.pdarraycreation.linspace(start: arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray, stop: arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray, num: arkouda.numpy.dtypes.int_scalars = 50, endpoint: None | bool = True, dtype: type | None = float64, axis: arkouda.numpy.dtypes.int_scalars = 0) arkouda.numpy.pdarrayclass.pdarray[source]

Return evenly spaced numbers over a specified interval.

Returns num evenly spaced samples, calculated over the interval [start, stop].

The endpoint of the interval can optionally be excluded.

Parameters:
  • start (Union[numeric_scalars, pdarray]) – The starting value of the sequence.

  • stop (Union[numeric_scalars, pdarray]) – The end value of the sequence, unless endpoint is set to False. In that case, the sequence consists of all but the last of num + 1 evenly spaced samples, so that stop is excluded. Note that the step size changes when endpoint is False.

  • num (int, optional) – Number of samples to generate. Default is 50. Must be non-negative.

  • endpoint (bool, optional) – If True, stop is the last sample. Otherwise, it is not included. Default is True.

  • dtype (dtype, optional) – Allowed for compatibility with numpy linspace, but anything entered is ignored. The output is always ak.float64.

  • axis (int, optional) – The axis in the result to store the samples. Relevant only if start or stop are array-like. By default (0), the samples will be along a new axis inserted at the beginning. Use -1 to get an axis at the end.

Returns:

There are num equally spaced samples in the closed interval [start, stop] or the half-open interval [start, stop) (depending on whether endpoint is True or False).

Return type:

pdarray

Raises:
  • TypeError – Raised if start or stop is not a float or a pdarray, or if num is not an int, or if endpoint is not a bool, or if dtype is anything other than None or float64, or axis is not an integer.

  • ValueError – Raised if axis is not a valid axis for the given data.

Examples

>>> import arkouda as ak
>>> ak.linspace(0,1,3)
array([0.00000000000000000 0.5 1.00000000000000000])
>>> ak.linspace(1,0,3)
array([1.00000000000000000 0.5 0.00000000000000000])
>>> ak.linspace(0,1,3,endpoint=False)
array([0.00000000000000000 0.33333333333333331 0.66666666666666663])
>>> ak.linspace(0,ak.array([2,3]),3)
array([array([0.00000000000000000 0.00000000000000000])
    array([1.00000000000000000 1.5]) array([2.00000000000000000 3.00000000000000000])])
>>> ak.linspace(ak.array([0,1]),3,3)
array([array([0.00000000000000000 1.00000000000000000])
    array([1.5 2.00000000000000000]) array([3.00000000000000000 3.00000000000000000])])
>>> ak.linspace(ak.array([0,1]),ak.array([2,3]),3)
array([array([0.00000000000000000 1.00000000000000000])
    array([1.00000000000000000 2.00000000000000000])
    array([2.00000000000000000 3.00000000000000000])])
arkouda.numpy.pdarraycreation.logspace(start: arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray, stop: arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.pdarrayclass.pdarray, num: arkouda.numpy.dtypes.int_scalars = 50, base: arkouda.numpy.dtypes.numeric_scalars = 10.0, endpoint: None | bool = True, dtype: type | None = float64, axis: None | arkouda.numpy.dtypes.int_scalars = 0) arkouda.numpy.pdarrayclass.pdarray[source]

Create a pdarray of numbers evenly spaced on a log scale.

Parameters:
  • start (Union[numeric_scalars, pdarray]) – The starting value of the sequence.

  • stop (Union[numeric_scalars, pdarray]) – The end value of the sequence, unless endpoint is set to False. In that case, the sequence consists of all but the last of num + 1 evenly spaced samples, so that stop is excluded. Note that the step size changes when endpoint is False.

  • num (int, optional) – Number of samples to generate. Default is 50. Must be non-negative.

  • base (numeric_scalars, optional) – the base of the log space, defaults to 10.0.

  • endpoint (bool, optional) – If True, stop is the last sample. Otherwise, it is not included. Default is True.

  • dtype (Union[None, float64]) – allowed for compatibility with numpy, but ignored. Outputs are always float

  • axis (int, optional) – The axis in the result to store the samples. Relevant only if start or stop are array-like. By default (0), the samples will be along a new axis inserted at the beginning. Use -1 to get an axis at the end.

Returns:

There are num equally spaced (logarithmically) samples in the closed interval base**``[start, stop]`` or the half-open interval base**``[start, stop)`` (depending on whether endpoint is True or False).

Return type:

pdarray

Raises:
  • TypeError – Raised if start or stop is not a float or a pdarray, or if num is not an int, or if endpoint is not a bool, or if dtype is anything other than None or float64, or axis is not an integer.

  • ValueError – Raised if axis is not a valid axis for the given data, or if base < 0.

See also

linspace

Notes

If start is greater than stop, the pdarray values are generated in descending order.

Examples

>>> import arkouda as ak
>>> ak.logspace(2,3,3,4)
array([16.00000000000000000 32.00000000000000000 64.00000000000000000])
>>> ak.logspace(2,3,3,4,endpoint=False)
array([16.00000000000000000 25.398416831491197 40.317473596635935])
>>> ak.logspace(0,1,3,4)
array([1.00000000000000000 2.00000000000000000 4.00000000000000000])
>>> ak.logspace(1,0,3,4)
array([4.00000000000000000 2.00000000000000000 1.00000000000000000])
>>> ak.logspace(0,1,3,endpoint=False)
array([1.00000000000000000 2.1544346900318838 4.6415888336127784])
>>> ak.logspace(0,ak.array([2,3]),3,base=2)
array([array([1.00000000000000000 1.00000000000000000])
    array([2.00000000000000000 2.8284271247461903])
    array([4.00000000000000000 8.00000000000000000])])
>>> ak.logspace(ak.array([0,1]),3,3,base=3)
array([array([1.00000000000000000 3.00000000000000000])
    array([5.196152422706632 9.00000000000000000])
    array([27.00000000000000000 27.00000000000000000])])
>>> ak.logspace(ak.array([0,1]),ak.array([2,3]),3,base=4)
array([array([1.00000000000000000 4.00000000000000000])
    array([4.00000000000000000 16.00000000000000000])
    array([16.00000000000000000 64.00000000000000000])])
arkouda.numpy.pdarraycreation.ones(size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | str, dtype: arkouda.numpy._typing._typing.StringDTypeTypes, max_bits: int | None = ...) arkouda.numpy.strings.Strings[source]
arkouda.numpy.pdarraycreation.ones(size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | str, dtype: arkouda.numpy._typing._typing.NumericDTypeTypes | type[arkouda.numpy.dtypes.bigint] = ..., max_bits: int | None = ...) arkouda.numpy.pdarrayclass.pdarray

Create a pdarray filled with ones.

Parameters:
  • size (int_scalars or tuple of int_scalars) – Size or shape of the array

  • dtype (Union[float64, int64, bool]) – Resulting array type, default ak.float64

  • max_bits (int) – Specifies the maximum number of bits; only used for bigint pdarrays Included for consistency, as ones are all zeros ending on a one, regardless of max_bits

Returns:

Ones of the requested size or shape and dtype

Return type:

pdarray

Raises:
  • TypeError – Raised if the supplied dtype is not supported

  • RuntimeError – Raised if the size parameter is neither an int nor a str that is parseable to an int.

  • ValueError – Raised if the rank of the given shape is not in get_array_ranks() or is empty

See also

zeros, ones_like

Examples

>>> import arkouda as ak
>>> ak.ones(5, dtype=ak.int64)
array([1 1 1 1 1])
>>> ak.ones(5, dtype=ak.float64)
array([1.00000000000000000 1.00000000000000000 1.00000000000000000
       1.00000000000000000 1.00000000000000000])
>>> ak.ones(5, dtype=ak.bool_)
array([True True True True True])

Notes

Logic for generating the pdarray is delegated to the ak.full method.

arkouda.numpy.pdarraycreation.ones_like(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.pdarrayclass.pdarray[source]

Create a one-filled pdarray of the same size and dtype as an existing pdarray.

Parameters:

pda (pdarray) – Array to use for shape and dtype

Returns:

Equivalent to ak.ones(pda.size, pda.dtype)

Return type:

pdarray

Raises:

TypeError – Raised if the pda parameter is not a pdarray.

See also

ones, zeros_like

Notes

Logic for generating the pdarray is delegated to the ak.ones method. Accordingly, the supported dtypes match are defined by the ak.ones method.

Examples

>>> import arkouda as ak
>>> ak.ones_like(ak.zeros(5,dtype=ak.int64))
array([1 1 1 1 1])
>>> ak.ones_like(ak.zeros(5,dtype=ak.float64))
array([1.00000000000000000 1.00000000000000000 1.00000000000000000
       1.00000000000000000 1.00000000000000000])
>>> ak.ones_like(ak.zeros(5,dtype=ak.bool_))
array([True True True True True])
arkouda.numpy.pdarraycreation.promote_to_common_dtype(arrays: List[arkouda.numpy.pdarrayclass.pdarray]) Tuple[Any, List[arkouda.numpy.pdarrayclass.pdarray]][source]

Promote a list of pdarrays to a common dtype.

Parameters:

arrays (List[pdarray]) – List of pdarrays to promote

Returns:

The common dtype of the pdarrays and the list of pdarrays promoted to that dtype

Return type:

dtype, List[pdarray]

Raises:

TypeError – Raised if any pdarray is a non-numeric type

See also

pdarray.promote_dtype

Examples

>>> import arkouda as ak
>>> a = ak.arange(5)
>>> b = ak.ones(5, dtype=ak.float64)
>>> dtype, promoted = ak.promote_to_common_dtype([a, b])
>>> dtype
dtype('float64')
>>> all(isinstance(p, ak.pdarray) and p.dtype == dtype for p in promoted)
True
arkouda.numpy.pdarraycreation.randint(low: arkouda.numpy.dtypes.numeric_scalars, high: arkouda.numpy.dtypes.numeric_scalars, size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] = 1, dtype=akint64, seed: arkouda.numpy.dtypes.int_scalars | None = None) arkouda.numpy.pdarrayclass.pdarray[source]

Generate a pdarray of randomized int, float, or bool values in a specified range bounded by the low and high parameters.

Parameters:
Returns:

Values drawn uniformly from the specified range having the desired dtype

Return type:

pdarray

Raises:
  • TypeError – Raised if dtype.name not in DTypes, size is not an int, low or high is not an int or float, or seed is not an int

  • ValueError – Raised if size < 0 or if high < low

Notes

Calling randint with dtype=float64 will result in uniform non-integral floating point values.

Ranges >= 2**64 in size is undefined behavior because it exceeds the maximum value that can be stored on the server (uint64)

Examples

>>> import arkouda as ak
>>> ak.randint(0, 10, 5, seed=1701)
array([6 5 1 6 3])
>>> ak.randint(0, 1, 3, seed=1701, dtype=ak.float64)
array([0.011410423448327005 0.73618171558685619 0.12367222192448891])
>>> ak.randint(0, 2, 5, seed=1701, dtype=ak.bool_)
array([False True False True False])
arkouda.numpy.pdarraycreation.random_strings_lognormal(logmean: arkouda.numpy.dtypes.numeric_scalars, logstd: arkouda.numpy.dtypes.numeric_scalars, size: arkouda.numpy.dtypes.int_scalars, characters: str = 'uppercase', seed: arkouda.numpy.dtypes.int_scalars | None = None) arkouda.numpy.strings.Strings[source]

Generate random strings with log-normally distributed lengths and with characters drawn from a specified set.

Parameters:
  • logmean (numeric_scalars) – The log-mean of the length distribution

  • logstd (numeric_scalars) – The log-standard-deviation of the length distribution

  • size (int_scalars) – The number of strings to generate

  • characters ((uppercase, lowercase, numeric, printable, binary)) – The set of characters to draw from

  • seed (int_scalars, optional) – Value used to initialize the random number generator

Returns:

The Strings object encapsulating a pdarray of random strings

Return type:

Strings

Raises:
  • TypeError – Raised if logmean is neither a float nor a int, logstd is not a float, seed is not an int, size is not an int, or if characters is not a str

  • ValueError – Raised if logstd <= 0 or size < 0

Notes

The lengths of the generated strings are distributed $Lognormal(\mu, \sigma^2)$, with \(\\mu = logmean\) and \(\\sigma = logstd\). Thus, the strings will have an average length of \(exp(\\mu + 0.5*\\sigma^2)\), a minimum length of zero, and a heavy tail towards longer strings.

Examples

>>> import arkouda as ak
>>> ak.random_strings_lognormal(2, 0.25, 5, seed=1)
array(['VWHJEX', 'BEBBXJHGM', 'RWOVKBUR', 'LNJCSDXD', 'NKEDQC'])
>>> ak.random_strings_lognormal(2, 0.25, 5, seed=1, characters='printable')
array(['eL96<O', ')o-GOe lR', ')PV yHf(', '._b3Yc&K', ',7Wjef'])
arkouda.numpy.pdarraycreation.random_strings_uniform(minlen: arkouda.numpy.dtypes.int_scalars, maxlen: arkouda.numpy.dtypes.int_scalars, size: arkouda.numpy.dtypes.int_scalars, characters: str = 'uppercase', seed: None | arkouda.numpy.dtypes.int_scalars = None) arkouda.numpy.strings.Strings[source]

Generate random strings with lengths uniformly distributed between minlen and maxlen, and with characters drawn from a specified set.

Parameters:
  • minlen (int_scalars) – The minimum allowed length of string

  • maxlen (int_scalars) – The maximum allowed length of string

  • size (int_scalars) – The number of strings to generate

  • characters ((uppercase, lowercase, numeric, printable, binary)) – The set of characters to draw from

  • seed (Union[None, int_scalars], optional) – Value used to initialize the random number generator

Returns:

The array of random strings

Return type:

Strings

Raises:

ValueError – Raised if minlen < 0, maxlen < minlen, or size < 0

Examples

>>> import arkouda as ak
>>> ak.random_strings_uniform(minlen=1, maxlen=5, seed=8675309, size=5)
array(['ECWO', 'WSS', 'TZG', 'RW', 'C'])
>>> ak.random_strings_uniform(minlen=1, maxlen=5, seed=8675309, size=5,
... characters='printable')
array(['2 .z', 'aom', '2d|', 'o(', 'M'])
arkouda.numpy.pdarraycreation.scalar_array(value: arkouda.numpy.dtypes.numeric_scalars | arkouda.numpy.dtypes.bool_scalars, dtype: numpy.dtype | type | str | arkouda.numpy.dtypes.bigint | None = None) arkouda.numpy.pdarrayclass.pdarray[source]

Create a pdarray from a single scalar value.

Parameters:
  • value (numeric_scalars) – Value to create pdarray from

  • dtype (np.dtype, type, str, bigint, or None) – The data type of the created array.

Returns:

pdarray with a single element

Return type:

pdarray

Examples

>>> import arkouda as ak
>>> ak.scalar_array(5)
array([5])
>>> ak.scalar_array(7.0)
array([7.00000000000000000])
Raises:

RuntimeError – Raised if value cannot be cast as dtype

arkouda.numpy.pdarraycreation.standard_normal(size: arkouda.numpy.dtypes.int_scalars, seed: None | arkouda.numpy.dtypes.int_scalars = None) arkouda.numpy.pdarrayclass.pdarray[source]

Draw real numbers from the standard normal distribution.

Parameters:
  • size (int_scalars) – The number of samples to draw (size of the returned array)

  • seed (int_scalars) – Value used to initialize the random number generator

Returns:

The array of random numbers

Return type:

pdarray

Raises:
  • TypeError – Raised if size is not an int

  • ValueError – Raised if size < 0

See also

randint

Notes

For random samples from \(N(\\mu, \\sigma^2)\), use:

(sigma * standard_normal(size)) + mu

Examples

>>> import arkouda as ak
>>> ak.standard_normal(3,1)
array([-0.68586185091150265 1.1723810583573377 0.5675841071420...])
arkouda.numpy.pdarraycreation.uniform(size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis], low: arkouda.numpy.dtypes.numeric_scalars = float(0.0), high: arkouda.numpy.dtypes.numeric_scalars = 1.0, seed: None | arkouda.numpy.dtypes.int_scalars = None) arkouda.numpy.pdarrayclass.pdarray[source]

Generate a pdarray with uniformly distributed random float values in a specified range.

Parameters:
  • size (Union[int_scalars, Tuple[int_scalars]) – The length or shape of the returned array

  • low (float_scalars) – The low value (inclusive) of the range, defaults to 0.0

  • high (float_scalars) – The high value (inclusive) of the range, defaults to 1.0

  • seed (int_scalars, optional) – Value used to initialize the random number generator

Returns:

Values drawn uniformly from the specified range

Return type:

pdarray

Raises:
  • TypeError – Raised if dtype.name not in DTypes, size is not an int, or if either low or high is not an int or float

  • ValueError – Raised if size < 0 or if high < low

Notes

The logic for uniform is delegated to the ak.randint method which is invoked with a dtype of float64

Examples

>>> import arkouda as ak
>>> ak.uniform(3,seed=1701)
array([0.011410423448327005 0.73618171558685619 0.12367222192448891])
>>> ak.uniform(size=3,low=0,high=5,seed=0)
array([0.30013431967121934 0.47383036230759112 1.0441791878997098])
arkouda.numpy.pdarraycreation.zeros(size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | str, dtype: arkouda.numpy._typing._typing.NumericDTypeTypes | type[arkouda.numpy.dtypes.bigint] = ..., max_bits: int | None = ...) arkouda.numpy.pdarrayclass.pdarray[source]
arkouda.numpy.pdarraycreation.zeros(size: arkouda.numpy.dtypes.int_scalars | Tuple[arkouda.numpy.dtypes.int_scalars, Ellipsis] | str, dtype: arkouda.numpy._typing._typing.StringDTypeTypes, max_bits: int | None = ...) Never

Create a pdarray filled with zeros.

Parameters:
  • size (int_scalars or tuple of int_scalars) – Size or shape of the array

  • dtype (all_scalars) – Type of resulting array, default ak.float64

  • max_bits (int) – Specifies the maximum number of bits; only used for bigint pdarrays Included for consistency, as zeros are represented as all zeros, regardless of the value of max_bits

Returns:

Zeros of the requested size or shape and dtype

Return type:

pdarray

Raises:
  • TypeError – Raised if the supplied dtype is not supported

  • RuntimeError – Raised if the size parameter is neither an int nor a str that is parseable to an int.

  • ValueError – Raised if the rank of the given shape is not in get_array_ranks() or is empty Raised if max_bits is not NONE and ndim does not equal 1

See also

ones, zeros_like

Examples

>>> import arkouda as ak
>>> ak.zeros(5, dtype=ak.int64)
array([0 0 0 0 0])
>>> ak.zeros(5, dtype=ak.float64)
array([0.00000000000000000 0.00000000000000000 0.00000000000000000
       0.00000000000000000 0.00000000000000000])
>>> ak.zeros(5, dtype=ak.bool_)
array([False False False False False])
arkouda.numpy.pdarraycreation.zeros_like(pda: arkouda.numpy.pdarrayclass.pdarray) arkouda.numpy.pdarrayclass.pdarray[source]

Create a zero-filled pdarray of the same size and dtype as an existing pdarray.

Parameters:

pda (pdarray) – Array to use for shape and dtype

Returns:

Equivalent to ak.zeros(pda.size, pda.dtype)

Return type:

pdarray

Raises:

TypeError – Raised if the pda parameter is not a pdarray.

See also

zeros, ones_like

Examples

>>> import arkouda as ak
>>> ak.zeros_like(ak.ones(5,dtype=ak.int64))
array([0 0 0 0 0])
>>> ak.zeros_like(ak.ones(5,dtype=ak.float64))
array([0.00000000000000000 0.00000000000000000 0.00000000000000000
       0.00000000000000000 0.00000000000000000])
>>> ak.zeros_like(ak.ones(5,dtype=ak.bool_))
array([False False False False False])