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, 2020 in Python by anonymous
• 220 points

edited May 18, 2020 by Gitika 6,210 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 10, 2019 in Python by sam
• 120 points
1,100 views
0 votes
1 answer
0 votes
1 answer

ValueError: could not broadcast input array from shape (360,270,3) into shape (360,280,3)

Hi@akhtar, In the above error it shows could not ...READ MORE

answered Apr 9, 2020 in Python by MD
• 95,460 points
20,451 views
+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, 2020 by Kalgi 3,993 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, 2020 in Python by Gitika
• 65,770 points
10,278 views
0 votes
0 answers

ValueError: could not broadcast input array from shape (224,224,9) into shape (224,224)

img_shape = 224 test_data = [] test_labels = [] for ...READ MORE

Nov 6, 2020 in Python by Eyosiyas
• 120 points
1,633 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,071 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP