Python Forum
How to print array indexes? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to print array indexes? (/thread-28786.html)



How to print array indexes? - Mark17 - Aug-03-2020

Is there a way I can get a numpy array to print out with index numbers like this? Thanks!


RE: How to print array indexes? - DeaD_EyE - Aug-03-2020

You could use numpy.ndenumerate.


RE: How to print array indexes? - buran - Aug-03-2020

please, don't post images of code, error, output, etc. Copy/paste in respective BBcode tags


RE: How to print array indexes? - Mark17 - Aug-03-2020

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


RE: How to print array indexes? - buran - Aug-03-2020

(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.


RE: How to print array indexes? - DeaD_EyE - Aug-03-2020

(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).


RE: How to print array indexes? - Mark17 - Aug-03-2020

Thanks DeaD_EyE!