I have the following python code:

```big_array = np.zeros(shape=(100,100), dtype=np.uint8)
mini_square = np.ones(shape=(2,2), dtype=np.uint8)

flattened_array = np.ravel(big_array)
flattened_minisquare = np.ravel(mini_square)

flattened_array[1:-1:10] = flattened_minisquare```

I get the following error:

```"ValueError: could not broadcast input array from shape (4) into shape (1000)"
``` Jun 14, 2019 in Python 26,369 views
What exactly are you trying to do?
I'm trying to insert a small array into a larger one without resizing.

## 1 answer to this question.

There are better ways of achieving the same. Have a look at this:

```import numpy as np

big_array = np.zeros(shape=(100,100), dtype=np.uint8)
mini_square = np.ones(shape=(2,2), dtype=np.uint8)

flattened_array = np.ravel(big_array)
flattened_minisquare = np.ravel(mini_square)

stepsize = 10
temp = np.zeros(stepsize + len(flattened_minisquare) - 1)
temp[-len(flattened_minisquare):] = flattened_minisquare

out = np.resize(temp, len(flattened_array))

print(out)
#[0. 0. 0. ... 0. 0. 0.]```

Hope this helps!

If you need to know more about Python, join Python online course certification today.

Thanks! answered Jun 14, 2019 by Faiza

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

Hey @Giorgio, You can try this hope this ...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