Skip to main content
  1. About
  2. For Teams
Asked
Viewed 86 times
0

I have an array in python which looks like:

Edit: Sorry, the data looks like follows:

1. [array([[[23,  2]]]), array([[[21,  2]],

               [[21,  3]],

               [[21,  4]],

               [[22,  4]],

               [[23,  4]],

               [[22,  4]],

               [[21,  3]]])]
2. [array([[[28, 26]],

       [[28, 27]],

       [[28, 28]],

       [[28, 29]],

       [[28, 30]],

       [[29, 30]],

       [[30, 30]],

       [[31, 30]],

       [[31, 29]],

       [[31, 28]],

       [[31, 27]],

       [[30, 26]],

       [[29, 26]]])]
    And after using print array_name[0] it looks like this:
        1. [[[23  2]]]
        2. [[[28 26]]

         [[28 27]]

         [[28 28]]

         [[28 29]]

         [[28 30]]

         [[29 30]]

         [[30 30]]

         [[31 30]]

         [[31 29]]

         [[31 28]]

         [[31 27]]

         [[30 26]]

         [[29 26]]]

Now I would like to read only the first part, i.e. [23 2] and [28 26]. How do it do that?

The list is divided into multiple arrays.

7
  • use print array_name[0] give its index to print the required data.
    Torrezzzz
    –  Torrezzzz
    2014-07-29 08:48:26 +00:00
    Commented Jul 29, 2014 at 8:48
  • Yes, I tried that way, but it prints the whole [[[X X]] [[X X]]] present in the array
    Okay Lolz
    –  Okay Lolz
    2014-07-29 08:49:55 +00:00
    Commented Jul 29, 2014 at 8:49
  • That is not valid python code. Please print and copy your array here so we can see what it actually looks like!
    theAlse
    –  theAlse
    2014-07-29 08:50:53 +00:00
    Commented Jul 29, 2014 at 8:50
  • I have updated the question, kind help me.
    Okay Lolz
    –  Okay Lolz
    2014-07-29 08:53:55 +00:00
    Commented Jul 29, 2014 at 8:53
  • How did u got array in python
    Sar009
    –  Sar009
    2014-07-29 08:59:31 +00:00
    Commented Jul 29, 2014 at 8:59

1 Answer 1

1
import numpy
l1 = [numpy.array([[[23, 2]]]), numpy.array([[[21, 2]], [[21, 3]], [[21, 4]], [[22, 4]], [[23, 4]],
     [[22, 4]], [[21, 3]]])]

l2 = [numpy.array([[[28, 26]], [[28, 27]],[[28, 28]], [[28, 29]], [[28, 30]], [[29, 30]], [[30, 30]], [[31, 30]],
     [[31, 29]], [[31, 28]],[[31, 27]], [[30, 26]],[[29, 26]]])]

print l1[0]     # -> [[[23  2]]]
print l2[0][0]  # -> [[28 26]]
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. I missed using the other [0].
I'm glad that I was able to help. Best regards, zinjaai

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.