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?

Supriya
  • 9
  • 3
binz
  • 49
  • 1
  • 7

1 Answers1

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]]
Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40