2017-07-31 06:05:26 8 Comments

I'm trying to reshape a numpy array as:

```
data3 = data3.reshape((data3.shape[0], 28, 28))
```

where `data3`

is:

```
[[54 68 66 ..., 83 72 58]
[63 63 63 ..., 51 51 51]
[41 45 80 ..., 44 46 81]
...,
[58 60 61 ..., 75 75 81]
[56 58 59 ..., 72 75 80]
[ 4 4 4 ..., 8 8 8]]
```

`data3.shape`

is `(52, 2352 )`

But I keep getting the following error:

```
ValueError: cannot reshape array of size 122304 into shape (52,28,28)
Exception TypeError: TypeError("'NoneType' object is not callable",) in <function _remove at 0x10b6477d0> ignored
```

What is happening and how to fix this error?

UPDATE:

I'm doing this to obtain `data3`

that is being used above:

```
def image_to_feature_vector(image, size=(28, 28)):
return cv2.resize(image, size).flatten()
data3 = np.array([image_to_feature_vector(cv2.imread(imagePath)) for imagePath in imagePaths])
```

imagePaths contains paths to all the images in my dataset. I actually want to convert the data3 to a `flat list of 784-dim vectors`

, however the

```
image_to_feature_vector
```

function converts it to a 3072-dim vector!!

### Related Questions

#### Sponsored Content

#### 8 Answered Questions

#### 1 Answered Questions

### Isomap Cant Reshape reshape array of size 72 into shape (8,8)

**2018-01-25 09:26:36****Pepin Peng****59**View**0**Score**1**Answer- Tags: image machine-learning reshape

#### 0 Answered Questions

### Processing very large images as numpy arrays

**2018-05-13 15:18:21****Suvidha****295**View**0**Score**0**Answer- Tags: python image numpy large-data numpy-memmap

#### 1 Answered Questions

### [SOLVED] ValueError: cannot reshape array of size 50176 into shape (1,224,224,3)

**2018-05-12 13:41:47****Madhi****4922**View**1**Score**1**Answer- Tags: python tensorflow keras resnet

#### 2 Answered Questions

### [SOLVED] Using numpy reshape to perform 3rd rank tensor unfold operation

**2018-04-22 19:55:40****vaspurakan****339**View**2**Score**2**Answer- Tags: python numpy image-processing linear-algebra tensor

#### 0 Answered Questions

#### 1 Answered Questions

#### 1 Answered Questions

#### 0 Answered Questions

### Tensorflow back_prop ValueError: setting an array element with a sequence

**2016-08-08 21:01:17****Gary Grey****384**View**0**Score**0**Answer- Tags: python arrays list arraylist tensorflow

## 2 comments

## @akilat90 2017-07-31 11:07:08

First, your input image's number of elements should match the number of elements in the desired feature vector.

Assuming the above is satisfied, the below should work:

## @akrama81 2017-07-31 17:26:36

Getting error: ValueError: cannot reshape array of size 52 into shape (1,784)

## @akilat90 2017-07-31 18:13:14

@akrama81 Do your images satisfy the mentioned requirement? (Total elements == 784)

## @akrama81 2017-07-31 22:11:35

If you mean feature vectors, then it's 2352. How to convert to 784?

## @akilat90 2017-08-01 10:48:54

@akrama81 I didn't get this:

`If you mean feature vectors, then it's 2352. How to convert to 784?`

What I said was that your input image should have a total number of`784`

(exactly) pixels if you want to convert it to a`[1,784]`

vector.## @Kaushik Nayak 2017-07-31 06:27:56

You can reshape the numpy matrix arrays such that before(a x b x c..n) = after(a x b x c..n). i.e the total elements in the matrix should be same as before, In your case, you can transform it such that transformed data3 has shape (156, 28, 28) or simply :-

Output is of the form

## @akrama81 2017-07-31 07:10:40

What is 156 in (156, 28, 28)??

## @akrama81 2017-07-31 07:12:27

I tried doing what you suggested but then when I do (trainData, testData, trainLabels, testLabels) = train_test_split( data3 / 255.0, labels, test_size=0.33), I get this error: ValueError: Found input variables with inconsistent numbers of samples: [156, 52] on that line.