Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print array indexes?
#1
Is there a way I can get a numpy array to print out with index numbers like this? Thanks!

Attached Files

Thumbnail(s)
   
Reply
#2
You could use numpy.ndenumerate.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
please, don't post images of code, error, output, etc. Copy/paste in respective BBcode tags
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
(Aug-03-2020, 01:44 PM)buran Wrote: please, don't post images of code, error, output, etc. Copy/paste in respective BBcode tags

What BBcode tags should be used for displaying a screenshot (file)?

(Aug-03-2020, 01:43 PM)DeaD_EyE Wrote: You could use numpy.ndenumerate.

That gave me something like <numpy.ndenumerate object at 0x0000014BE3A7F9D0> . How do I look at it?
Reply
#5
(Aug-03-2020, 02:28 PM)Mark17 Wrote: What BBcode tags should be used for displaying a screenshot (file)?
what exactly of NOT POST IMAGE (that is also screeshot) is unclear? copy/paste your code, errors, output, etc.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
(Aug-03-2020, 02:28 PM)Mark17 Wrote: That gave me something like <numpy.ndenumerate object at 0x0000014BE3A7F9D0> . How do I look at it?

It's an iterable like what enumerate is.
If you have learned the basics, you should know this simple things.

Please learn Python before you dive into numpy.

import numpy as np


data = np.random.random((10,3,2))

for index, value in np.ndenumerate(data):
    print(index, value)
So if you know Python, the example in the documentation of the function, looks similar to enumerate:

data = ["A", "B", "C"]
for index, value in enumerate(data):
    print(index, value)
And if you want to iterate only over the first dimension:
import numpy as np


data = np.random.random((10,3,2))
for index, value in enumerate(data):
    print(index, value)
This will give you 10 numpy.ndarrays with a shape of (3,2).
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#7
Thanks DeaD_EyE!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Comparing List values to get indexes Edward_ 7 1,082 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Replace columns indexes reading a XSLX file Larry1888 2 951 Nov-18-2022, 10:16 PM
Last Post: Pedroski55
  how to print all data from all data array? korenron 3 2,423 Dec-30-2020, 01:54 PM
Last Post: korenron
  I’m Flat out struggling to understand list indexes gr3yali3n 7 2,852 Jul-20-2020, 07:18 PM
Last Post: princetonits
  python 2D array creation and print issue developerbrain 5 2,755 May-15-2019, 01:38 PM
Last Post: developerbrain
  Print 2D Array dragu_stelian 3 2,663 Jan-27-2019, 06:09 PM
Last Post: aakashjha001

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020