ValueError could not broadcast input array from shape 4 1 into shape 4

0 votes
This code produces this error of broadcasting and I don't understand why. N is a number, C is a matrix 4x4, xvec_tra an array 4x1 and the result x should be a matrix 4xN.

x=np.zeros(shape=(4,int(N)), dtype=np.float64)
for i in range(0, int(N/2)):
    if i == 0:   
        x[:,0]=C * xvec_tra
        print(x[:,0])
else:
    x[:,i]=C*x[:,i-1]
    print(x[:,i])
Feb 13, 2020 in Python by Giorgio
• 120 points
9,923 views

1 answer to this question.

0 votes

Hey @Giorgio,

You can try this hope this will resolve your error.

import numpy as np

N=0

C=0

x=np.zeros(shape=(4,int(N)), dtype=np.float64)

for i in range(0, int(N/2)):

    if i == 0:   

        x[:,0]=C * xvec_tra

        print(x[:,0])

    else:

      x[:,i]=C*x[:,i-1]

      print(x[:,i])

print(N)
answered Feb 18, 2020 by Gitika
• 65,910 points

Related Questions In Python

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, 2020 by Kalgi 3,679 views
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,440 points
19,769 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,428 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,072 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
3,495 views
+1 vote
5 answers
0 votes
1 answer
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