0

I have an array as :

y_array= [array( [[1.008],[2.000],[5.8756],..[8.343]]),array([[3.5666],[2.5554],[5.888],...[3.2112]])] 

I wish to display a list as an output,but what I actually get is an array list.

My output is:

 y= [array([[1.008],[2.000],[5.8756],..[8.343]]) 

My expected output is

y=[[1.008],[2.000],[5.8756],..[8.343]] 

What I have tried is:

 checked_list=[['Col-2', 'Col-3']] for j in range(len(checked_list)): y_values.append('y'+str(j+1)) for k in range(len(y_values)): ydat = data[:, k + 1].reshape(m, 1) y_array.append(ydat) splitArraylist=[[y] for y in y_array] for i in range(len(checked_list)): self.XY(splitArraylist[i]) def XY(self,y): print(y) 

How to get list as an output instead of arraylist?

0

1 Answer 1

0

Your array is a list of lists, and the inner list has only 1 element, so use it's index to access the inner list, and then using list comprehension, convert each sublist to a list

import numpy as np y = [np.array([[1.008], [2.000], [5.8756],[8.343]])] #Convert each sublist in y[0] to a list res = [list(item) for item in y[0]] print(res) 

The output will be

[[1.008], [2.0], [5.8756], [8.343]] 
Sign up to request clarification or add additional context in comments.

2 Comments

Nah. y[0] is still an array. The OP clearly states "I wish to dispaly a list as an output,"
Damn! Should have read the question better! I fixed it Thanks @Sheldore Please take a look and consider upvoting if it is fine?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.