Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array dimension don't match
#1
Hey, I have this set of data:

Date                                              
2022-01-05 -0.012684 -0.011469 -0.013368 -0.004848
2022-01-06 -0.002342 -0.000050 -0.005381 -0.000241
2022-01-07 -0.009285 -0.001326 -0.008862 -0.001013
2022-01-08  0.001059  0.000000  0.000000  0.000000
2022-01-09  0.001064  0.000000  0.000000  0.000000
and the following one:
Date
2022-01-05   -0.021065
2022-01-06   -0.000423
2022-01-07   -0.004501
2022-01-10   -0.001295
2022-01-11    0.009867
                ...   
2022-09-27   -0.001411
2022-09-28    0.020688
2022-09-29   -0.021286
2022-09-30   -0.014126
2022-10-03    0.025965
Name: Adj Close, Length: 187, dtype: float64
and when running the following regression:
(beta, alpha) = stats.linregress(benchmark_ret.values,
                port_ret.values)[0:2]
I get this error:
ValueError                                Traceback (most recent call last)
<ipython-input-83-5fc43138a81e> in <module>
----> 1 (beta, alpha) = stats.linregress(benchmark_ret.values,
      2                 port_ret.values)[0:1]
      3 
      4 print("The portfolio beta is", round(beta, 4))

C:\Anaconda3\lib\site-packages\scipy\stats\_stats_mstats_common.py in linregress(x, y)
    143     #   ssxm = mean( (x-mean(x))^2 )
    144     #   ssxym = mean( (x-mean(x)) * (y-mean(y)) )
--> 145     ssxm, ssxym, _, ssym = np.cov(x, y, bias=1).flat
    146 
    147     # R-value

C:\Anaconda3\lib\site-packages\numpy\core\overrides.py in cov(*args, **kwargs)

C:\Anaconda3\lib\site-packages\numpy\lib\function_base.py in cov(m, y, rowvar, bias, ddof, fweights, aweights, dtype)
   2638         if not rowvar and y.shape[0] != 1:
   2639             y = y.T
-> 2640         X = np.concatenate((X, y), axis=0)
   2641 
   2642     if ddof is None:

C:\Anaconda3\lib\site-packages\numpy\core\overrides.py in concatenate(*args, **kwargs)

ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 187 and the array at index 1 has size 272
Actually, I tried with the same matrices dimensions and different values and it worked. Should I concatenate?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  x and y must have same first dimension, but have shapes (1,) and (50,) asja2010 5 2,636 Jan-12-2023, 07:24 PM
Last Post: deanhystad
  Strange error ValueError: dimension mismatch Anldra12 0 1,982 Aug-17-2021, 07:54 AM
Last Post: Anldra12
  ValueError: dimension mismatch Anldra12 0 3,411 Jul-17-2021, 04:46 PM
Last Post: Anldra12
  ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, hobbyist 17 150,761 Mar-22-2021, 10:27 AM
Last Post: hobbyist
  Error When Plotting ValueError: x and y must have same first dimension JoeDainton123 1 9,114 Oct-04-2020, 12:58 PM
Last Post: scidam
  Wrong dimension for my plot Jemeronimo 1 2,029 Apr-25-2019, 06:19 PM
Last Post: Larz60+
  Dictionary multi dimension support sripylearn 3 3,018 Aug-14-2018, 03:50 PM
Last Post: buran
  Fast method of searching a string in a multi-dimension array? draems 6 5,984 Feb-20-2017, 01:02 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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