ValueError: operands could not be broadcast together with shapes (3,) (1000,)

+1 vote

This is the part of my code, why it shows :ValueError: operands could not be broadcast together with shapes (3,) (1000,)

prets = []
pvols = []
for p in range (2500):
    weights = np.random.random(noa)
    weights /= np.sum(weights)
    prets.append(np.sum(data.mean() * weights) * 252)
    pvols.append(np.sqrt(np.dot(weights.T,
                                np.dot(data.cov() * 252, weights))))
    pret = np.array(prets)
    pvol = np.array(pvols)
May 17 in Python by anonymous
• 220 points

edited May 18 by Gitika 148 views

Hey, @Noman,

Could you please mention at which line of code the error you are facing? It will be helpful for me to investigate.

ValueError                                Traceback (most recent call last)
<ipython-input-107-7748785c18e9> in <module>
      4     weights = np.random.random(noa)
      5     weights /= np.sum(weights)
----> 6     prets.append(np.sum(data.mean() * weights) * 252)
      7     pvols.append(np.sqrt(np.dot(weights.T,
      8                                 np.dot(data.cov() * 252, weights))))

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
0 answers

Operands Could not be Broadcast with Shapes (19,)(0,) — KNN

I am working on how to use ...READ MORE

Nov 9, 2019 in Python by sam
• 120 points
140 views
0 votes
1 answer
0 votes
1 answer
+1 vote
0 answers

ValueError: could not broadcast input array from shape (2) into shape (5)

I was implementing gillespie algorithm and when ...READ MORE

Dec 23, 2019 in Python by anonymous
• 130 points

reshown Jan 13 by Kalgi 1,100 views
0 votes
1 answer

ValueError: could not broadcast input array from shape (4,1) into shape (4)

Hey @Giorgio, You can try this hope this ...READ MORE

answered Feb 18 in Python by Gitika
• 29,690 points
843 views
0 votes
1 answer

Python error: No handlers could be found for logger “xhtml2pdf”

The only solution is to define a ...READ MORE

answered Sep 5, 2018 in Python by Priyaj
• 57,530 points
490 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 963 views
0 votes
0 answers
+4 votes
6 answers