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
- How to reset index in a pandas dataframe? [duplicate]
- How to iterate over rows in a DataFrame in Pandas
- pandas read_json: “If using all scalar values, you must pass an index”
- numpy max vs amax vs maximum
- The difference between comparison to np.nan and isnull()
- 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
- Most efficient way to find mode in numpy array
- How to groupby based on two columns in pandas?
- How to replace NaN values by Zeroes in a column of a Pandas Dataframe?
- How do I read CSV data into a record array in NumPy?
- How to normalize a NumPy array to a unit vector?
- DataFrame constructor not properly called! error
- ImportError: numpy.core.multiarray failed to import
- Error”Can only compare identically-labeled Series objects” and sort_index
- ImportError: numpy.core.multiarray failed to import
- size of NumPy array
- Convert a tensor to numpy array in Tensorflow?
- convert nan value to zero
- Most efficient way to map function over numpy array
- Is there a NumPy function to return the first index of something in an array?
- Get total of Pandas column
- Type error: cannot convert the series to
- Cannot convert list to array: ValueError: only one element tensors can be converted to Python scalars
- Change column type in pandas
- Calculating Covariance with Python and Numpy
- Dump a NumPy array into a csv file
- Inverse of a matrix using numpy
- AttributeError: Can only use .dt accessor with datetimelike values
- xlrd.biffh.XLRDError: Excel xlsx file; not supported
- Pandas – DataFrame object is not callable
- 3-dimensional array in numpy
- How do you get the magnitude of a vector in Numpy?
- ‘list’ object has no attribute ‘shape’
- What is the difference between np.mean and tf.reduce_mean?
- How do I combine two dataframes?
- How to calculate rolling / moving average using python + NumPy / SciPy?
- Normalize columns of pandas data frame
- Converting strings to floats in a DataFrame
- Normalize columns of pandas data frame
- Pandas join issue: columns overlap but no suffix specified
- How to apply a function to two columns of Pandas dataframe
- What does ‘index 0 is out of bounds for axis 0 with size 0’ mean?
- Convert categorical data in pandas dataframe
- Moving average or running mean
- ValueError: x and y must be the same size
- Loading a file with more than one line of JSON into Pandas
- NumPy List Comprehension Syntax
- Linear regression with matplotlib / numpy
- pandas DataFrame: replace nan values with average of columns
- RuntimeError: module compiled against API version a but this version of numpy is 9
- Pandas error “Can only use .str accessor with string values”
- numpy-equivalent of list.pop?
- How to get row number in dataframe in Pandas?
- Efficiently sorting a numpy array in descending order?
- How to add column to numpy array
- Unknown format code ‘f’ for object of type ‘str’- Folium
- Compute a confidence interval from sample data
- Pandas: sum up multiple columns into one column without last column
- How do I compute derivative using Numpy?
- Convert Pandas Column to DateTime
- ImportError: cannot import name NUMPY_MKL
- built-in range or numpy.arange: which is more efficient?
- Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support
- Move column by name to front of table in pandas
- Must have equal len keys and value when setting with an iterable
- Convert a 1D array to a 2D array in numpy
- Pandas dataframe groupby plot
- inverting image in Python with OpenCV
- How to print the full NumPy array, without truncation?
- Convert list of dictionaries to a pandas DataFrame
- Python Pandas : pivot table with aggfunc = count unique distinct
- AttributeError: ‘Series’ object has no attribute ‘split’ error in sending emails