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 9,688 views

## 1 answer to this question.

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)```
• 65,930 points

## Python Error ""ValueError: could not broadcast input array from shape (4) into shape (1000)""

There are better ways of achieving the ...READ MORE

+1 vote

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

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

## 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

## 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

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

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

## Lowercase in Python

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

+1 vote