moptipy.spaces package¶
In this package, some pre-defined search and solution spaces are provided.
These spaces implement the base class Space
, which defines the API for creating, copying, storing, and comparing (for equality) of data structures that can be used to represent either points in the search space or candidate solutions in the solution space.
The following pre-defined spaces are currently available:
BitStrings
, the space of n-dimensional bit stringsIntSpace
, a space of n-dimensional integer strings, where each element is between (and including) a minimum and a maximum value (inclusive)Permutations
is a special version of theIntSpace
where all elements are permutations of a base stringblueprint
. This means that it can represent permutations both with and without repetitions. Depending on the base string, each element may occur an element-specific number of times. For the base string (-1, -1, 2, 7, 7, 7), for example, -1 may occur twice, 2 can occur once, and 7 three times.OrderedChoices
is a combination of permutations and combinations. There are n choices of one or multiple different values each. The choices are either disjoint or identical. An element from the space picks one value per choice. The order of the elements matters.VectorSpace
is the space of n-dimensional floating point number vectors
Submodules¶
moptipy.spaces.bitstrings module¶
An implementation of a bit string based search space.
- class moptipy.spaces.bitstrings.BitStrings(dimension)[source]¶
Bases:
NPArraySpace
A space where each element is a bit string (
numpy.ndarray
).With such a space, discrete optimization can be realized.
>>> s = BitStrings(5) >>> print(s.dimension) 5 >>> print(s.dtype) bool >>> print(s.create()) [False False False False False] >>> print(s.to_str(s.create())) FFFFF >>> print(s.from_str(s.to_str(s.create()))) [False False False False False]
- create()[source]¶
Create a bit string filled with False.
- Return type:
- Returns:
the string
>>> from moptipy.spaces.bitstrings import BitStrings >>> s = BitStrings(8) >>> v = s.create() >>> print(s.to_str(v)) FFFFFFFF >>> print(v.dtype) bool
- from_str(text)[source]¶
Convert a string to a bit string.
- Parameters:
text (
str
) – the text- Return type:
- Returns:
the vector
- Raises:
TypeError – if text is not a str
ValueError – if text cannot be converted to a valid vector
moptipy.spaces.intspace module¶
An implementation of an integer string based search space.
- class moptipy.spaces.intspace.IntSpace(dimension, min_value, max_value)[source]¶
Bases:
NPArraySpace
A space where each element is a one-dimensional numpy integer array.
Such spaces can serve as basis for implementing combinatorial optimization and can be extended to host permutations. Their elements are instances of
numpy.ndarray
.>>> s = IntSpace(5, -4, 99) >>> print(s.dimension) 5 >>> print(s.min_value) -4 >>> print(s.max_value) 99 >>> print(s.dtype) int8 >>> s = IntSpace(5, 2, 200) >>> print(s.dtype) uint8 >>> s = IntSpace(5, 2, 202340) >>> print(s.dtype) int32
- create()[source]¶
Create an integer vector filled with the minimal value.
- Return type:
- Returns:
the vector
>>> from moptipy.spaces.intspace import IntSpace >>> s = IntSpace(dimension=12, min_value=5, max_value=332) >>> v = s.create() >>> print(s.to_str(v)) 5;5;5;5;5;5;5;5;5;5;5;5 >>> print(v.dtype) int16
- log_parameters_to(logger)[source]¶
Log the parameters of this space to the given logger.
- Parameters:
logger (
KeyValueLogSection
) – the logger for the parameters- Return type:
>>> from moptipy.utils.logger import InMemoryLogger >>> space = IntSpace(7, -5, 5) >>> space.dimension 7 >>> with InMemoryLogger() as l: ... with l.key_values("C") as kv: ... space.log_parameters_to(kv) ... text = l.get_log() >>> text[-2] 'max: 5' >>> text[-3] 'min: -5' >>> text[-4] 'dtype: b' >>> text[-5] 'nvars: 7' >>> text[-6] 'class: moptipy.spaces.intspace.IntSpace' >>> text[-7] 'name: ints7bm5to5' >>> len(text) 8
- n_points()[source]¶
Get the number of possible different integer strings.
- Return type:
- Returns:
(max_value - min_value + 1) ** dimension
>>> print(IntSpace(4, -1, 3).n_points()) 625
- validate(x)[source]¶
Validate an integer string.
- Parameters:
x (
ndarray
) – the integer string- Raises:
TypeError – if the string is not an
numpy.ndarray
.ValueError – if the shape or data type of the vector is wrong or any of its element is not finite or if an element is out of the bounds.
- Return type:
moptipy.spaces.nparrayspace module¶
The base class for spaces based on numpy arrays.
- class moptipy.spaces.nparrayspace.NPArraySpace(dimension, dtype)[source]¶
Bases:
Space
A space where each element is a one-dimensional
numpy.ndarray
.Such spaces can serve as basis for implementing combinatorial optimization and can be extended to host permutations.
>>> import numpy as npx >>> s = NPArraySpace(9, npx.dtype(int)) >>> print(s.dimension) 9 >>> print(s.dtype) int64 >>> print(s.create()) [0 0 0 0 0 0 0 0 0] >>> print(s.to_str(s.create())) 0;0;0;0;0;0;0;0;0 >>> print(s.from_str(s.to_str(s.create()))) [0 0 0 0 0 0 0 0 0]
- from_str(text)[source]¶
Convert a string to a vector.
- Parameters:
text (
str
) – the text- Return type:
- Returns:
the vector
- Raises:
TypeError – if text is not a str
ValueError – if text cannot be converted to a valid vector
- log_parameters_to(logger)[source]¶
Log the parameters of this space to the given logger.
- Parameters:
logger (
KeyValueLogSection
) – the logger for the parameters- Return type:
>>> from moptipy.utils.logger import InMemoryLogger >>> import numpy as npx >>> dt = npx.dtype(float) >>> dt.char 'd' >>> space = NPArraySpace(10, dt) >>> space.dimension 10 >>> with InMemoryLogger() as l: ... with l.key_values("C") as kv: ... space.log_parameters_to(kv) ... text = l.get_log() >>> text[-2] 'dtype: d' >>> text[-3] 'nvars: 10' >>> text[-4] 'class: moptipy.spaces.nparrayspace.NPArraySpace' >>> text[-5] 'name: ndarray10d' >>> len(text) 6
- validate(x)[source]¶
Validate a numpy nd-array.
- Parameters:
x (
ndarray
) – the numpy vector- Raises:
TypeError – if the string is not an
numpy.ndarray
.ValueError – if the shape or data type of the vector is wrong or any of its element is not finite.
- Return type:
moptipy.spaces.ordered_choices module¶
Permutations of a selection (or ordered choices) as strings.
Imagine the following situation: We have a rectangle (two-dimensional) and want to place n other, smaller rectangles into it. Let each rectangle have a unique ID from 1 to n. We can use a permutation of 1..n to represent the order in which we insert the small rectangles. However, maybe we want to also be able to rotate a rectangle by 90° and then place it. So additionally to the insertion order, we may want to remember whether the rectangle is placed as-is or rotated. We could do this with a “permutation of choices”, where we can place either i or -i for i from 1..n. A negative value could mean “insert rotated by 90°” whereas a positive value means “insert as is”. So we have n (disjoint) choices, each of which with two options. From each choice, we can pick one value. Then the order in which the values appear marks the insertion order. So this is basically a “super space” of permutations, as it deals both with the order of the elements and their values (resulting from the selected choice).
A string consists of n elements. There also are n so-called “selections,” each of which being a set offering a choice from different values. Any two selections must either be entirely disjoint or equal. The final string must contain one value from each selection.
Let’s say that we have three selections, e.g., [1, 2, 3], [4, 5], and [6]. Then the “selection permutations” space contains, e.g., the string [4, 3, 6] or [2, 5, 6] – one value from each selection. It does not contain [1, 3, 5], though, because that string has two values from the first selection.
This space is a super space of the permutations
, i.e., the space of permutations with repetitions. Sometimes (check OrderedChoices.is_compatible_with_permutations()
), the search operators defined in package permutations
can also be applied to the elements of our space here, although they may not be able to explore the space in-depth (as they will not alter the choices and only permute the chosen elements).
- class moptipy.spaces.ordered_choices.OrderedChoices(selections)[source]¶
Bases:
IntSpace
Permutations of selections, stored as
numpy.ndarray
.- blueprint:
Final
[ndarray
]¶ The blueprint array, i.e., an ordered array holding the smallest value possible for each choice.
- create()[source]¶
Create an ordered choice, equal to
blueprint
.- Return type:
- Returns:
the ordered choices, an instance of
numpy.ndarray
.
>>> perm = OrderedChoices([[1, 3], [2, 4], [1, 3], [7, 5]]) >>> x = perm.create() >>> print(perm.to_str(x)) 1;1;2;5
- is_compatible_with_permutations()[source]¶
Check whether for compatibility with permutations with repetitions.
Or, in other words, check whether the operators in package
permutations
can safely be applied for elements of this space here.Permutations with repetitions are permutations where each element occurs exactly a given number of times. Our implementation of this space (
permutations
) ensures that there are at least two different elements. The unary and binary search operators defined in packagepermutations
rely on this fact. While these operators cannot explore the depth of the permutations-of-selections space here, they can be “compatible” to this space: Any element of the permutation-of-selections space is, by definition, a permutation with repetitions, as it contains one concrete manifestation per choice. Applying, for instance, aop1_swap2
operation to it, which swaps two different elements, still yields a valid and different permutation-of-selections. However, since the operators inpermutations
always enforce that the resulting point is different from their input and only permute the elements, this can only work if we have at least two disjoint choices in our space definition. The function here checks this.- Return type:
- Returns:
True if and only if the operators in package
permutations
can safely be applied to elements of this space
- log_parameters_to(logger)[source]¶
Log the parameters of this space to the given logger.
- Parameters:
logger (
KeyValueLogSection
) – the logger for the parameters- Return type:
- n_points()[source]¶
Get the number of possible different permutations of the choices.
- Return type:
- Returns:
[factorial(dimension) / Product(factorial(count(e)) for all e)] * Product(len(e)*count(e) for all e)
- static signed_permutations(n)[source]¶
Create a space for signed permutations with values 1..n.
You would be much better off using
signed_permutations
instead of this space for signed permutations, though.- Parameters:
n (
int
) – the range of the values- Return type:
- Returns:
the permutations space
>>> perm = OrderedChoices.signed_permutations(3) >>> perm.validate(perm.blueprint) >>> print(perm.blueprint) [-3 -2 -1] >>> print(perm.n_points()) # 3! * (2 ** 3) = 6 * 8 = 48 48 >>> perm = OrderedChoices.signed_permutations(4) >>> perm.validate(perm.blueprint) >>> print(perm.blueprint) [-4 -3 -2 -1] >>> print(perm.n_points()) # 4! * (2 ** 4) = 24 * 16 = 384 384
- validate(x)[source]¶
Validate a permutation of selections.
- Parameters:
x (
ndarray
) – the integer string- Raises:
TypeError – if the string is not an
numpy.ndarray
.ValueError – if the element is not a valid permutation of the given choices
- Return type:
- blueprint:
moptipy.spaces.permutations module¶
An implementation of a search space for permutations of a base string.
The base string can be a string where each element occurs exactly once, e.g., [0, 1, 2, 3] or [0, 7, 2, 5]. It could also be a string where some or all elements occur multiple times, e.g., a permutation with repetition, such as [0, 7, 7, 4, 5, 3, 3, 3] or [0, 0, 1, 1, 2, 2]. Search operators working on elements of this space are given in module moptipy.operators.permutations
.
- moptipy.spaces.permutations.KEY_BASE_STRING: Final[str] = 'baseString'¶
the base string to be permuted
- moptipy.spaces.permutations.KEY_REPETITIONS: Final[str] = 'repetitions'¶
the number of times each value must occur
- class moptipy.spaces.permutations.Permutations(base_string)[source]¶
Bases:
IntSpace
A space of permutations of a base string stored as
numpy.ndarray
.This class includes standard permutations of the form 0, 1, 2, …, n-1, but also permutations with repetitions. The idea is that a base string is defined, i.e., an array of integer values. In this array, some values may appear twice, some may be missing. For example, [1, 3, 5, 5, 7] is a proper base string. The space defined over this base string would then contain values such as [1, 3, 5, 5, 7], [1, 5, 3, 5, 7], [7, 5, 5, 3, 1] and so on. Basically, it will contain all strings that can be created by shuffling the base string. These strings have in common that they contain exactly all the values from the base string and contain them exactly as same as often as they appear in the base string. The space defined upon the above base string therefore would contain 5! / (1! * 1! * 2! * 1!) = 120 / 2 = 60 different strings.
The permutation space defined above can be created as follows:
>>> perm = Permutations([1, 3, 5, 5, 7]) >>> print(perm.to_str(perm.blueprint)) 1;3;5;5;7 >>> print(perm) permOfString >>> print(perm.n_points()) 60
Another example is this:
>>> perm = Permutations((1, 2, 3, 3, 2)) >>> print(perm.to_str(perm.blueprint)) 1;2;2;3;3 >>> print(perm) permOfString >>> print(perm.n_points()) 30
If you want to create a permutation with repetitions, e.g., where each of the n=4 values from 0 to 3 appear exactly 3 times, you can use the utility method with_repetitions:
>>> perm = Permutations.with_repetitions(4, 3) >>> print(perm.to_str(perm.blueprint)) 0;0;0;1;1;1;2;2;2;3;3;3 >>> print(perm) perm4w3r >>> print(perm.n_points()) 369600
If you instead want to create standard permutations, i.e., where each value from 0 to n-1 appears exactly once, you would do:
>>> perm = Permutations.standard(5) >>> print(perm.to_str(perm.blueprint)) 0;1;2;3;4 >>> print(perm) perm5 >>> print(perm.n_points()) 120
- create()[source]¶
Create a permutation equal to the base string.
The result is of the form [0, 0, 1, 1, 1, 2, 2…].
- Return type:
- Returns:
the permutation of the base string
>>> perm = Permutations([1, 5, 2, 2, 4, 3, 4]) >>> x = perm.create() >>> print(perm.to_str(x)) 1;2;2;3;4;4;5
- has_repetitions()[source]¶
Return whether elements occur repeatedly in the base string.
- Return type:
- Returns:
True if at least one element occurs more than once, False otherwise
- is_dense()[source]¶
Check if all values in min..max appear in the permutation.
- Return type:
- Returns:
True if the permutation is dense in the sense that all values from self.min_value to self.max_value appear.
- log_parameters_to(logger)[source]¶
Log the parameters of this space to the given logger.
- Parameters:
logger (
KeyValueLogSection
) – the logger for the parameters- Return type:
- n()[source]¶
Get the number of different values in the base string.
- Return type:
- Returns:
the number of different values in the base string
- n_points()[source]¶
Get the number of possible different permutations of the base string.
- Return type:
- Returns:
factorial(dimension) / Product(factorial(count(e)) for all e)
>>> print(Permutations([0, 1, 2, 3, 0, 1, 2, 3]).n_points()) 2520
- static standard(n)[source]¶
Create a space for permutations of 0..n-1.
- Parameters:
n (
int
) – the range of the values- Return type:
- Returns:
the permutations space
- validate(x)[source]¶
Validate a permutation of the base string.
- Parameters:
x (
ndarray
) – the integer string- Raises:
TypeError – if the string is not an
numpy.ndarray
.ValueError – if the element is not a valid element of this permutation space, e.g., if the shape or data type of x is wrong, if an element is outside of the bounds, or if an element does not occur exactly the prescribed amount of times
- Return type:
moptipy.spaces.signed_permutations module¶
A search space for signed permutations of a base string.
The base string can be a string where each element occurs exactly once, e.g., [1, 2, 3] or [7, 2, 5]. It could also be a string where some or all elements occur multiple times, e.g., a permutation with repetition, such as [1, 7, 7, 4, 5, 3, 3, 3] or [3, 3, 1, 1, 2, 2]. Each element may then occur either in its original (positive) value in a string or in its negated (negative) form.
Notice that a signed permutation can never include the element 0. Therefore, some methods have different semantics compared to those in class Permutations
.
Search operators working on elements of this space are given in module moptipy.operators.signed_permutations
, but several of those in moptipy.operators.permutations
should work as well.
- moptipy.spaces.signed_permutations.KEY_UNSIGNED_MIN: Final[str] = 'unsignedMin'¶
the unsigned minimum
- class moptipy.spaces.signed_permutations.SignedPermutations(base_string)[source]¶
Bases:
IntSpace
Signed permutations of a base string stored as
numpy.ndarray
.This class includes standard permutations of the form 1, 2, …, n, but also permutations with repetitions. The idea is that a base string is defined, i.e., an array of integer values. In this array, some values may appear twice, some may be missing. For example, [1, 3, 5, 5, 7] is a proper base string. The space defined over this base string would then contain values such as [1, 3, 5, 5, 7], [1, 5, 3, 5, 7], [7, 5, 5, 3, 1] and so on. Basically, it will contain all strings that can be created by shuffling the base string and/or negating some or all of the values, i.e., [-1, 3, -5, 5, -7] would also be possible. These strings have in common that they contain exactly all the values from the base string and contain them exactly as same as often as they appear in the base string. They can never contain 0.
The space defined upon the above base string contains (2 ** 5) * 5! / (1! * 1! * 2! * 1!) = 32 * 120 / 2 = 1920 different strings.
The permutation space defined above can be created as follows:
>>> perm = SignedPermutations([1, 3, 5, 5, 7]) >>> print(perm.to_str(perm.blueprint)) 1;3;5;5;7 >>> print(perm) signedPermOfString >>> print(perm.n_points()) 1920
Another example is this:
>>> perm = SignedPermutations((1, 2, 3, 3, 2)) >>> print(perm.to_str(perm.blueprint)) 1;2;2;3;3 >>> print(perm) signedPermOfString >>> print(perm.n_points()) 960
If you want to create a permutation with repetitions, e.g., where each of the n=4 values from 1 to 4 appear exactly 3 times, you can use the utility method with_repetitions:
>>> perm = SignedPermutations.with_repetitions(4, 3) >>> print(perm.to_str(perm.blueprint)) 1;1;1;2;2;2;3;3;3;4;4;4 >>> print(perm) signedPerm4w3r >>> print(perm.n_points()) 1513881600
If you instead want to create standard permutations, i.e., where each value from 1 to n appears exactly once, you would do:
>>> perm = SignedPermutations.standard(5) >>> print(perm.to_str(perm.blueprint)) 1;2;3;4;5 >>> print(perm) signedPerm5 >>> print(perm.n_points()) 3840
Different from normal permutations with repetitions, it is allowed that signed permutations with repetitions contain the same element, as long as their length is larger than 1.
>>> perm = SignedPermutations([1, 1]) >>> print(perm.to_str(perm.blueprint)) 1;1 >>> x = perm.create() >>> perm.validate(x) >>> x[0] = -1 >>> perm.validate(x) >>> x[1] = -1 >>> perm.validate(x) >>> x[0] = 1 >>> perm.validate(x)
>>> try: ... perm = SignedPermutations([1]) ... except ValueError as ve: ... print(ve) base_string must contain at least two different elements or have at least length 2, but is [1].
- create()[source]¶
Create a permutation equal to the base string.
The result is of the form [1, 1, 2, 2, 2, 3, 3…].
- Return type:
- Returns:
the permutation of the base string
>>> perm = SignedPermutations([1, 5, 2, 2, 4, 3, 4]) >>> x = perm.create() >>> print(perm.to_str(x)) 1;2;2;3;4;4;5
- has_repetitions()[source]¶
Return whether elements occur repeatedly in the base string.
- Return type:
- Returns:
True if at least one element occurs more than once, False otherwise
- is_dense()[source]¶
Check if all values in min..max appear in the permutation.
- Return type:
- Returns:
True if the permutation is dense in the sense that all values from self.min_value to self.max_value appear.
- log_parameters_to(logger)[source]¶
Log the parameters of this space to the given logger.
- Parameters:
logger (
KeyValueLogSection
) – the logger for the parameters- Return type:
- n()[source]¶
Get the number of different values in the base string.
- Return type:
- Returns:
the number of different values in the base string
- n_points()[source]¶
Get the number of possible different permutations of the base string.
- Return type:
- Returns:
(2 ** dimension) * factorial(dimension) / Product(factorial(count(e)) for all e)
>>> print(SignedPermutations([1, 2, 3, 1, 2, 3]).n_points()) 5760
- static standard(n)[source]¶
Create a space for permutations of 1..n.
Notice that this method is different compared to the method
standard()
of classPermutations
in that it starts the permutations at 1, not at 0.- Parameters:
n (
int
) – the range of the values- Return type:
- Returns:
the permutations space
- validate(x)[source]¶
Validate a signed permutation of the base string.
- Parameters:
x (
ndarray
) – the integer string- Raises:
TypeError – if the string is not an
numpy.ndarray
.ValueError – if the element is not a valid element of this permutation space, e.g., if the shape or data type of x is wrong, if an element is outside of the bounds, or if an element does not occur exactly the prescribed amount of times
- Return type:
- static with_repetitions(n, repetitions)[source]¶
Create a space for permutations of 1..n with repetitions.
Notice that this method is different compared to the method
with_repetitions()
of classPermutations
in that it starts the permutations at 1, not at 0.- Parameters:
- Return type:
- Returns:
the permutations space
moptipy.spaces.vectorspace module¶
An implementation of an box-constrained n-dimensional continuous space.
- moptipy.spaces.vectorspace.KEY_LOWER_BOUND: Final[str] = 'lb'¶
the log key for the lower bound, i.e., the minimum permitted value
- moptipy.spaces.vectorspace.KEY_UPPER_BOUND: Final[str] = 'ub'¶
the log key for the upper bound, i.e., the maximum permitted value
- class moptipy.spaces.vectorspace.VectorSpace(dimension, lower_bound=0.0, upper_bound=1.0, dtype=dtype('float64'))[source]¶
Bases:
NPArraySpace
A vector space where each element is an n-dimensional real vector.
Such spaces are useful for continuous optimization. The vectors are implemented as one-dimensional
numpy.ndarray
of length n. A vector space is constraint by a box which defines the minimum and maximum permitted value for each of its n elements.>>> s = VectorSpace(3) >>> print(s.dimension) 3 >>> print(s.dtype) float64 >>> print(s.lower_bound) [0. 0. 0.] >>> print(s.upper_bound) [1. 1. 1.] >>> print(s.lower_bound_all_same) True >>> print(s.upper_bound_all_same) True >>> s = VectorSpace(2, -1.0, 5.0) >>> print(s.lower_bound) [-1. -1.] >>> print(s.upper_bound) [5. 5.] >>> s = VectorSpace(2, [-1.0, -2.0], 5.0) >>> print(s.lower_bound) [-1. -2.] >>> print(s.upper_bound) [5. 5.] >>> print(s.lower_bound_all_same) False >>> print(s.upper_bound_all_same) True
- clipped(func)[source]¶
Wrap a function ensuring that all vectors are clipped to the bounds.
This function is useful to ensure that only valid vectors are passed to
evaluate()
.
- log_bounds(logger)[source]¶
Log the bounds of this space to the given logger.
- Parameters:
logger (
KeyValueLogSection
) – the logger for the parameters- Return type:
>>> from moptipy.utils.logger import InMemoryLogger >>> import numpy as npx >>> space = VectorSpace(2, -5.0, [2.0, 3.0]) >>> with InMemoryLogger() as l: ... with l.key_values("C") as kv: ... space.log_bounds(kv) ... text = l.get_log() >>> text[-2] 'ub: 2;3' >>> text[-3] 'lb: -5' >>> len(text) 4
- log_parameters_to(logger)[source]¶
Log the parameters of this space to the given logger.
- Parameters:
logger (
KeyValueLogSection
) – the logger for the parameters- Return type:
>>> from moptipy.utils.logger import InMemoryLogger >>> import numpy as npx >>> space = VectorSpace(2, -5.0, [2.0, 3.0]) >>> space.dimension 2 >>> space.dtype.char 'd' >>> with InMemoryLogger() as l: ... with l.key_values("C") as kv: ... space.log_parameters_to(kv) ... text = l.get_log() >>> text[-2] 'ub: 2;3' >>> text[-3] 'lb: -5' >>> text[-4] 'dtype: d' >>> text[-5] 'nvars: 2' >>> text[-6] 'class: moptipy.spaces.vectorspace.VectorSpace' >>> text[-7] 'name: r2d' >>> len(text) 8
- n_points()[source]¶
Get an upper bound for the number of different values in this space.
- Return type:
- Returns:
We return the approximate number of finite floating point numbers while ignoring the box constraint. This value here therefore is an upper bound.
>>> import numpy as npx >>> print(VectorSpace(3, dtype=npx.dtype(npx.float64)).n_points()) 6267911251143764491534102180507836301813760039183993274367
- validate(x)[source]¶
Validate a vector.
- Parameters:
x (
ndarray
) – the real vector- Raises:
TypeError – if the string is not an
numpy.ndarray
.ValueError – if the shape of the vector is wrong or any of its element is not finite.
- Return type: