vector
Module Contents
Classes
Base class used to store the entries inside a vector and perform basic opearations. |
- class vector.Vector(n, x=None)
Base class used to store the entries inside a vector and perform basic opearations.
- Attributes:
- sizeint
Size of the vector
- datanp.ndarray
The vector stored as a numpy array
- add(y)
Return the sum of input numpy vector with the Vector() object
Extended summary of the add method, if needed.
Note
Any specific note for the user
New in version 0.3.0.
Deprecated since version 0.5.0: Warnings for users if an object is deprecated. add will be removed in lsdo_project_template 1.0.0, it will be replaced by add_new since the latter works with many more types of arrays.
- Parameters:
- ynp.ndarray
Numpy vector to be added
- Returns:
- np.ndarray
Sum of the input vector and the Vector() object
- Raises:
- ValueError
If shape of y is not same as the shape of the Vector() object.
- Warns:
- DeprecationWarning
Use this optional section if your method has any warnings.
Warning
Ensure that the numpy vector y has the same shape as the Vector() object.
See also
iaddAdd inplace a numpy vector to a Vector() object
Notes
Return values: add() method returns a numpy object whereas iadd() does not return anything
Examples
An extended example the functions like a tutorial.
Initialize the vector object.
>>> vec = Vector(10)
Print to see the data inside the initialized vector.
>>> print(vec.data) [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
Now test the add() method.
>>> import numpy as np >>> x = np.ones((10,)) >>> y = vec.add(x) >>> print(y) [10. 10. 10. 10. 10. 10. 10. 10. 10. 10.]
- iadd(y)
Add inplace a numpy vector to a Vector() object
- Parameters:
- ynp.ndarray
Numpy vector to be added
See also
addReturn the sum of input numpy vector with a Vector() object
Examples
>>> vec = Vector(10) >>> print(vec.data) >>> import numpy as np >>> x = np.ones((10,)) >>> vec.iadd(x) >>> print(vec.data)
- scalar_mult(c)
Return a scalar multiple of the Vector() object as a numpy array
- Parameters:
- c: int or float
Scalar to be multiplied
- Returns:
- znp.ndarray
Scalar multiple of the Vector() object
Examples
>>> import numpy as np >>> vec = Vector(10, np.ones((10,))) >>> print(vec.data) >>> z = vec.scalar_mult(5.) >>> print(z)