rand#
- AnsMath.rand(nrow, ncol=None, dtype=<class 'numpy.float64'>, name=None, asarray=False)#
Create a vector or a matrix where all values are random.
- Parameters:
- nrow
int
Number of rows.
- ncol
int
,optional
Number of columns. If a value is specified, a matrix is returned.
- dtype
np.dtype
,optional
NumPy data type of the object. The options are
np.double
,np.int32
, andnp.int64
. The default isnp.double
.- name
str
,optional
AnsMath object name. The default is
None
, in which case a name is automatically generated.- asarraybool,
optional
Whether to return a NumPy array rather than an AnsMath object. The default is
False
.
- nrow
- Returns:
AnsVec
,AnsMat
,or
numpy.ndarray
AnsMath vector, NumPy array vector, AnsMath matrix, or NumPy array matrix, depending on the value for the
asarray
parameter and if a value for thencol
parameter is specified.
Examples
Create a vector where all values are random.
>>> import ansys.math.core.math as pymath >>> mm = pymath.AnsMath() >>> vec = mm.rand(10)
Create a matrix where all values are random.
>>> mat = mm.rand(10, 10)