Python Forum
How to do matrix subtraction
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to do matrix subtraction
#1
Hi,
I have below two arrays
1. my test data
2. my prediction data

print(y_pred2)
[0 2 0 2 0 0]
print(y_test)
 y
30  0
31  0
32  0
33  0
34  0
35  0

y_test.shape, y_pred2.shape,type(y_test), type(y_pred2)

((6, 1), (6,), pandas.core.frame.DataFrame, numpy.ndarray)

Now I want to calculate the delta between my test data & predict data

error=y_test-y_pred2

it give below error:
ValueError                                Traceback (most recent call last)
<ipython-input-118-3919f3823c1c> in <module>()
----> 1 error=y_test-y_pred2

C:\Users\user\Anaconda3\lib\site-packages\pandas\core\ops.py in f(self, other, axis, level, fill_value)
   1223     def f(self, other, axis=default_axis, level=None, fill_value=None):
   1224 
-> 1225         other = _align_method_FRAME(self, other, axis)
   1226 
   1227         if isinstance(other, pd.DataFrame):  # Another DataFrame

C:\Users\user\Anaconda3\lib\site-packages\pandas\core\ops.py in _align_method_FRAME(left, right, axis)
   1146 
   1147         if right.ndim == 1:
-> 1148             right = to_series(right)
   1149 
   1150         elif right.ndim == 2:

C:\Users\user\Anaconda3\lib\site-packages\pandas\core\ops.py in to_series(right)
   1136         else:
   1137             if len(left.columns) != len(right):
-> 1138                 raise ValueError(msg.format(len(left.columns), len(right)))
   1139             right = left._constructor_sliced(right, index=left.columns)
   1140         return right

ValueError: Unable to coerce to Series, length must be 1: given 6
kindly some help, many thanks in advance
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  list subtraction d8a988 3 2,113 Oct-23-2020, 04:49 PM
Last Post: Gribouillis
  numpy subtraction of two arrays devenuro 1 11,685 Sep-24-2018, 12:55 AM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020