- discretize.utils.mkvc(x, n_dims=1, **kwargs)¶
Creates a vector with specified dimensionality.
This function converts a
numpy.ndarrayto a vector. In general, the output vector has a dimension of 1. However, the dimensionality can be specified if the user intends to carry out a dot product with a higher order array.
The output vector, with at least
Here, we reorganize a simple 2D array as a vector and demonstrate the impact of the n_dim argument.
>>> from discretize.utils import mkvc >>> import numpy as np
>>> a = np.random.rand(3, 2) >>> a array([[0.33534155, 0.25334363], [0.07147884, 0.81080958], [0.85892774, 0.74357806]])
>>> v = mkvc(a) >>> v array([0.33534155, 0.07147884, 0.85892774, 0.25334363, 0.81080958, 0.74357806])
In Higher dimensions:
>>> for ii in range(1, 4): ... v = mkvc(a, ii) ... print('Shape of output with n_dim =', ii, ': ', v.shape) Shape of output with n_dim = 1 : (6,) Shape of output with n_dim = 2 : (6, 1) Shape of output with n_dim = 3 : (6, 1, 1)