Use of numpy.matrix not recommended
- Dominant language
- JetBrains MPS
- Stars
- 192
- Forks
- 70
- PR merge metrics
- No merged PRs in 30d
Description
The use of `numpy.matrix` is discuraged since numpy 1.15
From the docs([1.15](https://docs.scipy.org/doc/numpy-1.15/reference/generated/numpy.matrix.html#numpy.matrix) / [stable](https://numpy.org/doc/stable/reference/generated/numpy.matrix.html)):
> Note
> It is no longer recommended to use this class, even for linear algebra. Instead use regular arrays. The class may be removed in the future.
Using regular arrays gives some problems, like in the [first example](http://coin-or.github.io/CyLP/#modeling-example):
```python
import numpy as np
from cylp.cy import CyClpSimplex
from cylp.py.modeling.CyLPModel import CyLPArray
s = CyClpSimplex()
# Add variables
x = s.addVariable('x', (3, 1)) # should be 2-d now
y = s.addVariable('y', (2, 1)) # should be 2-d now
# Create coefficients and bounds
A = np.array([[1., 2., 0], [1., 0, 1.]]) # use array
B = np.array([[1., 0, 0], [0, 0, 1.]]) # use array
D = np.array([[1., 2.], [0, 1]]) # use array
a = CyLPArray([5, 2.5])
b = CyLPArray([4.2, 3])
x_u = CyLPArray([2., 3.5])
# Add constraints
s += A @ x <= a # use matmul operator
s += 2 <= B @ x + D @ y <= b # use matmul operator
s += y >= 0
s += 1.1 <= x[1:3] <= x_u
# Set the objective function
c = CyLPArray([1., -2., 3.])
s.objective = c @ x + 2 * y.sum() # use matmul operator
# Solve using primal Simplex
s.primal()
print(s.primalVariableSolution['x'])
```
```
Traceback (most recent call last):
File "/path/to/example.py", line 20, in
s += A @ x <= a
ValueError: matmul: Input operand 1 does not have enough dimensions (has 0, gufunc core with signature (n?,k),(k,m?)->(n?,m?) requires 1)
Process finished with exit code 1
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.