-1

I have this array and would like to keep just the numbers.

[array([-0.69]), array([-0.82]), array([ 0.00268447]),
 array([ 1.25709725]), array([ 0.00460194]), array([-0.00191748])]

I have tried strip and replace commands but to no avail. I have also followed this : Removing Characters from python Output . Any more ideas?

Community
  • 1
  • 1
pg19
  • 21
  • 6

2 Answers2

0

You seem to have a list of numpy.arrays with a single element each. You can turn that into a numpy.array like this:

l = [array([-0.69]), array([-0.82]), array([ 0.00268447]),
    array([ 1.25709725]), array([ 0.00460194]), array([-0.00191748])]
arr = numpy.array(l)

To print this array, you could do this:

print(', '.join(map(str, arr)))
fmarc
  • 1,706
  • 15
  • 20
0

Converting each element to float.

In [1]: from numpy import array
In [2]: a = [array([-0.69]), array([-0.82]), array([ 0.00268447]),
   ....:  array([ 1.25709725]), array([ 0.00460194]), array([-0.00191748])]

In [3]: map(float,a)
Out[1]: [-0.69, -0.82, 0.00268447, 1.25709725, 0.00460194, -0.00191748]

You can do like this.

Rahul K P
  • 15,740
  • 4
  • 35
  • 52