## ValueError: cannot reshape array of size 784 into shape (16,16)

Of course, the solution is easier than you think.

ValueError: cannot reshape array of size 784 into shape (16,16).

`28 x 28 = 784`

Therefore, you need to reshape into the format `(28,28)`

rather than `(16,16)`

## ValueError: cannot reshape array of size 408 into shape (256,256)

You load something from a `.mat`

file, and select the 'face_mask' variable. Without the relevant file we can't examine or recreate that.

` data = loadmat(os.path.join(input_path, name))`

render_mask = data['face_mask']

then you load something else (`load_mask`

is unknown), and run the unknown `split_segmask`

function:

` seg_mask = load_mask(os.path.join(mask_path, name))`

face_segmask, hairear_mask, _ = split_segmask(seg_mask)

According to the error, `face_segmask`

is (3,136)

` face_remain_mask = np.zeros_like(face_segmask)`

`resize`

does not operate in-place, so this does not change `face_segmask`

:

` np.resize(face_segmask,(2,204))`

Then you try to reshape it instead. Why (2,204) in the resize, and (256,256) here. `resize`

can change the total number of elements; `reshape`

can't. I think you need to reread the function documentation!

` face_segmask = face_segmask.reshape((256,256))`

The error here says `face_segmask`

has 408 elements (flatten view of (3,136)). That's not all the same as 256*256. `reshape`

is NOT a image 'resizer'.

` face_remain_mask[(face_segmask - render_mask) == 1] = 1`

your original error go here, with (3,136) (256,256) shapes. What where you imagining would happen here? The arrays don't have any dimensions in common. How's it supposed to do ELEMENT-WISE subtraction. By subtraction we mean `3 - 4 = -1`

, not some sort of set or image "removal".

I'm not sure you understand array shapes, and specifically why your arrays have shapes they have. And it isn't clear what you trying to do with this subtraction.

I can imagine the (256,256) array representing an image. But what's the (3,136) array? How is that supposed to relate to or map on the (256,256) space. What's the 3 dimension? 3 color channels perhaps? And the 136? indices of some sort?

In your other questions you appear to be processing images, trying perhaps to identify features like 'faces' or 'hair'.

## cannot reshape array of size 89401 into shape (299,299,3)

In order to get 3 channels `np.dstack`

:

`image = np.dstack([image.reshape(299,299)]*3)`

Or if you want only one channel

`image.reshape(299,299)`

## ValueError: cannot reshape array of size 40000 into shape (1,32,32,3)

If size of image data is 40000 and not equal 1x32x32x3 (One image with width and height, 32 x 32, and RGB format), you reshape it and then got the error.

`>>> import numpy as np`

>>> a = np.array([1 for i in range(40000)], dtype=np.int8)

>>> a.size

40000

>>> a.reshape((1, 32, 32, 3))

Traceback (most recent call last):

File "<interactive input>", line 1, in <module>

ValueError: cannot reshape array of size 40000 into shape (1,32,32,3)

>>> 40000 != 1*32*32*3

True

You may need to resize image to 32x32 RGB firstly.

## ValueError: cannot reshape array of size 0

When reshaping, if you are keeping the same data contiguity and just reshaping the box, you can reshape your data with

`data_reconstructed = data_clean.reshape((10,1500,77))`

if you are changing the contiguity from one axis to another, you will need to add a permutation of the axes beforehand https://numpy.org/doc/stable/reference/generated/numpy.transpose.html

### Related Topics

Pandas Get the Most Frequent Values of a Column

How to Write List Elements into a Tab-Separated File

Making a Matrix in Python 3 Without Numpy Using Inputs

Making a Dictionary from Each Line in a File

How to Read a Specific Line from a Text File in Python

Delete Every Non Utf-8 Symbols from String

Check If a Key Exists in a Bucket in S3 Using Boto3

Pandas Merge - How to Avoid Duplicating Columns

How to Overwrite the Previous Print to Stdout

How to Install Python Packages from the Tar.Gz File Without Using Pip Install

Counting the No. of Black to White Pixels in the Image Using Opencv

Update Json Element in Json Object Using Python

Using SQL Server Stored Procedures from Python (Pyodbc)

I Want to Reshape 2D Array into 3D Array

How to Import a File in Python With Spaces in the Name

Finding the Max Value in a Two Dimensional Array

How to Mention a User in Discord.Py

How to Continue a Loop After Catching Exception in Try ... Except