You are trying to index into a scalar (non-iterable) value:
[y[1] for y in y_test] # ^ this is the problem
When you call [y for y in test]
you are iterating over the values already, so you get a single value in y
.
Your code is the same as trying to do the following:
y_test = [1, 2, 3] y = y_test[0] # y = 1 print(y[0]) # this line will fail
I’m not sure what you’re trying to get into your results array, but you need to get rid of [y[1] for y in y_test]
.
If you want to append each y in y_test to results, you’ll need to expand your list comprehension out further to something like this:
[results.append(..., y) for y in y_test]
Or just use a for loop:
for y in y_test: results.append(..., y)
Related Posts:
- ValueError: Unknown label type: ‘continuous’
- Convert pandas dataframe to NumPy array
- ImportError: Missing required dependencies [‘numpy’]
- Python Pandas – Missing required dependencies [‘numpy’] 1
- ‘DataFrame’ object has no attribute ‘sort’
- ‘DataFrame’ object has no attribute ‘sort’
- TypeError: cannot unpack non-iterable int objec
- ‘DataFrame’ object has no attribute ‘sort’
- What is dtype(‘O’), in pandas?
- What is dtype(‘O’), in pandas?
- TypeError: ‘DataFrame’ object is not callable
- ValueError: ‘object too deep for desired array’
- What does axis in pandas mean?
- How to take column-slices of dataframe in pandas
- Normalize data in pandas
- Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?
- pandas create new column based on values from other columns / apply a function of multiple columns, row-wise
- Building multi-regression model throws error: `Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).`
- Coalesce values from 2 columns into a single column in a pandas dataframe
- Concat DataFrame Reindexing only valid with uniquely valued Index objects
- Replacing Pandas or Numpy Nan with a None to use with MysqlDB
- Difference between data type ‘datetime64[ns]’ and ‘
- Merging two DataFrames
- Calculate weighted average using a pandas/dataframe
- vectorize conditional assignment in pandas dataframe
- how to sort pandas dataframe from one column
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- ImportError: DLL load failed: The specified module could not be found
- ImportError: DLL load failed: The specified module could not be found
- Renaming column names in Pandas
- How to reset index in a pandas dataframe? [duplicate]
- Delete a column from a Pandas DataFrame
- Import Error: No module named numpy
- How to deal with SettingWithCopyWarning in Pandas
- How to deal with SettingWithCopyWarning in Pandas
- Constructing pandas DataFrame from values in variables gives “ValueError: If using all scalar values, you must pass an index”
- How to iterate over rows in a DataFrame in Pandas
- pandas read_json: “If using all scalar values, you must pass an index”
- How to iterate over rows in a DataFrame in Pandas
- ValueError: setting an array element with a sequence
- Writing a pandas DataFrame to CSV file
- numpy max vs amax vs maximum
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- Writing a pandas DataFrame to CSV file
- What exactly does numpy.exp() do? [closed]
- The difference between comparison to np.nan and isnull()
- Difference between import numpy and import numpy as np
- Adding new column to existing DataFrame in Python pandas
- Modifing data while using iterrows() does not work
- ImportError: No module named pandas
- How to change the order of DataFrame columns?
- What is the purpose of meshgrid in Python / NumPy?
- why numpy.ndarray is object is not callable in my simple for python loop
- numpy division with RuntimeWarning: invalid value encountered in double_scalars
- Numpy ValueError: setting an array element with a sequence. This message may appear without the existing of a sequence?
- How to change the order of DataFrame columns?
- numpy: Invalid value encountered in true_divide
- ImportError: No module named pandas. Pandas installed pip
- python numpy ValueError: operands could not be broadcast together with shapes
- What does `ValueError: cannot reindex from a duplicate axis` mean?
- Pandas DataFrame Groupby two columns and get counts
- How to fix ‘Object arrays cannot be loaded when allow_pickle=False’ for imdb.load_data() function?
- How do I create an empty array/matrix in NumPy?
- Most efficient way to find mode in numpy array
- How can I use the apply() function for a single column?
- How to show all columns’ names on a large pandas dataframe?
- Convenient way to deal with ValueError: cannot reindex from a duplicate axis
- How to groupby based on two columns in pandas?
- TypeError: unhashable type: ‘numpy.ndarray’
- “Series objects are mutable and cannot be hashed” error
- Could not install packages due to a “Environment error :[error 13]: permission denied : ‘usr/local/bin/f2py'”
- numpy division with RuntimeWarning: invalid value encountered in double_scalars
- How does numpy.newaxis work and when to use it?
- How to deal with SettingWithCopyWarning in Pandas
- numpy matrix vector multiplication
- Converting list to numpy array
- Merging dataframes on index with pandas
- How do I read CSV data into a record array in NumPy?
- ImportError: No module named pandas
- TypeError: ‘Series’ objects are mutable, thus they cannot be hashed problemwith column
- Create a Pandas Dataframe by appending one row at a time
- How to replace NaN values by Zeroes in a column of a Pandas Dataframe?
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- data type not understood
- How do you do natural logs (e.g. “ln()”) with numpy in Python?
- How do I read CSV data into a record array in NumPy?
- Plotting a 2D heatmap with Matplotlib
- How to normalize a NumPy array to a unit vector?
- Convert Python dict into a dataframe
- Should I use np.absolute or np.abs?
- re.sub erroring with “Expected string or bytes-like object”
- Creating an empty Pandas DataFrame, then filling it?
- How do I select rows from a DataFrame based on column values?
- How do I select rows from a DataFrame based on column values?
- What does numpy.random.seed(0) do?
- DataFrame constructor not properly called! error
- Pandas group-by and sum
- How do I get the row count of a Pandas DataFrame?
- ImportError: numpy.core.multiarray failed to import