1

I have a numpy array that looks like this:

[  7.1101   6.5277   9.5186   8.0032   6.8598   9.3829   8.4764   9.5781
   7.4862   6.0546   6.7107  15.164    6.734    9.4084   6.6407   6.3794
   7.3654   6.1301   7.4296   8.0708   7.1891  21.27     6.4901   7.3261
   6.5649  19.945   13.828   11.957   14.176   23.203    6.2524   7.5894
  10.2482   6.8918   9.2111   8.9334   9.0959   6.6063  13.836    7.3534
   6.4069   7.8825  12.708    6.7737   8.8247   8.0931   6.0702   6.8014
  12.7      6.5416   8.5402   6.3077   8.4239   8.6031   7.3328   7.3589
   7.2742   6.6397  10.3102  10.4536   9.8254   6.1793  22.279   15.908
  19.959    8.2182   9.2951  11.236    6.4994  21.341   11.136    8.3345
   7.0062   8.2259   6.0269   7.5479   8.5386   6.0365  11.274    6.1077
   6.7292   6.1884   7.3557  10.7687   7.5159   9.5172  10.1802   7.002
   6.5204   6.0594   6.7077   8.6366   6.8707   6.3054   9.2934  14.394
   6.4369]

And a numpy array that looks like this:

      prices
0   17.59200
1    9.13020
2   13.66200
3   11.85400
4    6.82330
5   11.88600
6    4.34830
7   12.00000
8    6.59870
9    3.81660
10   3.25220
11  15.50500
12   3.15510
13   7.22580
14   0.71618
15   3.51290
16   5.30480
17   0.56077
18   3.65180
19   5.38930
20   3.13860
21  21.76700
22   4.26300
23   5.18750
24   3.08250
25  22.63800
26  13.50100
27   7.04670
28  14.69200
29  24.14700
..       ...
67   7.77540
68   1.01730
69  20.99200
70   6.67990
71   4.02590
72   1.27840
73   3.34110
74  -2.68070
75   0.29678
76   3.88450
77   5.70140
78   6.75260
79   2.05760
80   0.47953
81   0.20421
82   0.67861
83   7.54350
84   5.34360
85   4.24150
86   6.79810
87   0.92695
88   0.15200
89   2.82140
90   1.84510
91   4.29590
92   7.20290
93   1.98690
94   0.14454
95   9.05510
96   0.61705

And I keep getting this error when trying to subtract the first array from the other:

ValueError: Shape of passed values is (97, 97), indices imply (1, 97)

What can I do to match the shape of the arrays together so I can subtract them? I am newish to numpy and am stuck on this problem

2
  • First off, the first group of numbers you posted look like they're in a list, not a numpy array - I would check that. It's true that you could convert one to the other, but what you pasted here is not a numpy array. Further, the second object looks like a pandas Series, which is neither a list or a numpy array. The difference between those two object types could be your problem. Finally, I don't see anything here with a size of (97, 97) - either the question needs to be updated with data to reflect the error message, or the error message needs to be updated to reflect the data in this question Commented Mar 7, 2017 at 23:16
  • It looks like the second one is actually a pandas data structure of some sort. Commented Mar 7, 2017 at 23:42

1 Answer 1

1

Search for "numpy reshape" and you'll soon have your answer. ;)

my_array.reshape(m, n)

returns the array reshaped as requested (m rows, n columns).

Note that it doesn't modify the original my_array object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.