You provide a huge amount of lines of code, but this actually sums to a single issue: You are extracting 3 integers from next_day_open_values, nx, ny = next_day_open_values.shape. Numpy's reshape expects an array as input, not an integer or single value.
Parameters: numpy.reshape(a, newshape, order='C')
a : array_like - Array to be reshaped.
I doubt you are trying to get a vector of a single integer repeating for the nx*ny shape. Furthermore, if you turn the input into an array, and perform the same operation, you'll run into ValueError because you cannot reshape an array of size 1 into a specific shape.
I believe this might work, but I don't know what next_day_open_values is:
next_day_open_values_s, nx, ny = next_day_open_values.shape
next_day_open_values = next_day_open_values.reshape(next_day_open_values_s,nx*ny)
Answer from Celius Stingher on Stack OverflowYou can convert your list to a numpy array and then reshape it with numpy.reshape
import numpy as np
# Convert to numpy array
w_train = np.array(w_train)
w_test = np.array(w_train)
# Reshape
w_train = np.reshape(w_train, (2404,28,224,224,3))
w_test = np.reshape(w_test, (601,28,224,224,3))
reshape is a methode under numpy's library and as the error printed in your terminal the object list has no methode defined as reshape
import numpy as np
w_train=np.array(x_train)
then you can simply use the reshape function without any error :
w_train=x_train.reshape((2404,28,224,224,3))
you can check the reshape characteristics in this link for more understanding of the methode
Seeing AttributeError: 'Dataset' object has no attribute 'reshape' when using "dataset.get_nearest_examples"
Getting Attribute error " 'int' object has no attribute 'shape' - Chapter 03
Python error 'int' object has no attribute 'shape' - Stack Overflow
Getting "AttributeError: 'int' object has no attribute 'shape'" in predict
Solution was linked on reshaped method on documentation page.
Insted of Y.reshape(-1,1) you need to use:
Y.values.reshape(-1,1)
The solution is indeed to do:
Y.values.reshape(-1,1)
This extracts a numpy array with the values of your pandas Series object and then reshapes it to a 2D array.
The reason you need to do this is that pandas Series objects are by design one dimensional. Another solution if you would like to stay within the pandas library would be to convert the Series to a DataFrame which would then be 2D:
Y = pd.Series([1,2,3,1,2,3,4,32,2,3,42,3])
scaler = StandardScaler()
Ys = scaler.fit_transform(pd.DataFrame(Y))
Your current approach involves nested loops and reshaping, which can be quite slow. Instead of using np.append within loops, consider using numpy.roll for efficient pixel shifting.
Using numpy.roll, you can achieve the desired image shifts using numpy.roll. Here’s an example of how to do it:
import numpy as np
from scipy.ndimage.interpolation import shift
from keras.datasets import mnist
# Load MNIST dataset
(x_train, y_train), _ = mnist.load_data()
def shift_image(image, shift_x, shift_y):
return np.roll(image, (shift_x, shift_y), axis=(0, 1)).reshape(-1)
# Create shifted copies for each direction
X_train_expansion = []
y_train_expansion = []
for shift_x, shift_y in ((0, 1), (0, -1), (1, 0), (-1, 0)):
for image, label in zip(x_train, y_train):
shifted_image = shift_image(image, shift_x, shift_y)
X_train_expansion.append(shifted_image)
y_train_expansion.append(label)
X_train_expansion = np.array(X_train_expansion)
y_train_expansion = np.array(y_train_expansion)
According to the error message, the problem is with the output variable in the shift function. While it occurs several layers down it appears that output is an int, while output.shape indicates it should be an array (a class of objects that has a shape attribute).
Looking at the shift docs, I see the signature is:
shift(input, shift, output=None, ...)
where output is supposed to be an array. shift can be a scalar, or a sequence.
You call it with:
shift(image, shift_x, shift_y)
Your 3rd argument is shift_y, not a output array.
the fix? Calling the shift function with the right kinds of arguments, the kinds specified in the documentation.
shift(image, (shift_x, shift_y))
I try to face swap using ace++ workflow, but this error shows up - 'NoneType' object has no attribute 'reshape'.
This is workflow.
https://drive.google.com/file/d/1dCWpJFvieTGgpHnw7wd0KF69qtAs3ONo/view?usp=sharing