-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?

6
  • 1
    array as in numpy.array? Commented Jun 1, 2016 at 10:15
  • 2
    That is a list of arrays (probably numpy arrays). There are no characters that you could strip. Do you want a list of numbers or an array of numbers? Commented Jun 1, 2016 at 10:16
  • 1
    To clarify: You seem to have a list of numpy.arrays with one element each. Commented Jun 1, 2016 at 10:16
  • Whats the output you want? Commented Jun 1, 2016 at 10:17
  • Would this be a similar example? Turning [[123], [2], [79]] into [123, 2, 79]? Commented Jun 1, 2016 at 10:20

2 Answers 2

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)))
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.