Python Forum
Programming neural networks with Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Programming neural networks with Python
#1
I'm just trying my hand at neural networks, I'm a beginner! And I have a problem with a Python statement. The Statement looks like
targets[int(zeileListe[0])] = 1! I do not understand this Statement. I createt a small Programm and it looks like:

import numpy as np

zeile = "5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,18,18,18,126,136,175,26,166,255,247,127,0,0,0,0,0,0,0,0,0,0,0,0,30,36,94,154,170,253,253,253,253,253,225,172,253,242,195,64,0,0,0,0,0,0,0,0,0,0,0,49,238,253,253,253,253,253,253,253,253,251,93,82,82,56,39,0,0,0,0,0,0,0,0,0,0,0,0,18,219,253,253,253,253,253,198,182,247,241,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,80,156,107,253,253,205,11,0,43,154,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,1,154,253,90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,139,253,190,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,190,253,70,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,35,241,225,160,108,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,81,240,253,253,119,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,45,186,253,253,150,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,93,252,253,187,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,253,249,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,46,130,183,253,253,207,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,148,229,253,253,253,250,182,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,114,221,253,253,253,253,201,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,23,66,213,253,253,253,253,198,81,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,171,219,253,253,253,253,195,80,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,172,226,253,253,253,253,244,133,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,136,253,253,253,212,135,132,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
zeileListe = zeile.split(",")

print("Daten1\t",zeileListe)

O_KNOTEN = 10
targets = np.zeros(O_KNOTEN) #1
print("Daten\t",targets)
targets[int(zeileListe[0])] = 1 #2
print("\nDaten3\t",[int(zeileListe[0])])
print("\nDaten2\t",targets)
The output of this programm is:

Output:
Daten [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] Daten3 [5] Daten2 [0. 0. 0. 0. 0. 1. 0. 0. 0. 0.]
zeile is the first line of a CSV-File and the first Number is "5", this is clear for me!

But now the statement #2 take this number "5" as an Index and put a "1" to the List targets. This is what I do not understand, how the Index 5 is used.

Can someone explain it how this is done in the satement #2?

With best regards,
Reinhold
Reply
#2
" and ' are can only be used on strings that are one line. For multiple lines use """.
""" This is a multiple
line quote."""
Reply
#3
Look at line 11. You know that zelleListe[0] is 5. Mentally substitute that and go out a level. Now int(5) is also 5. So, simplifying again, targets[5] = 1. Got it?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Star [HELP] The Application of Deep Neural Networks MistyhV1 0 356 May-05-2024, 02:22 PM
Last Post: MistyhV1
  Python programming and a dataset ErnestTBass 9 5,318 Feb-05-2019, 06:51 PM
Last Post: buran
  Developing larger Neural Networks Chriskelm 2 2,959 Nov-03-2018, 02:47 AM
Last Post: brighteningeyes
  Centralities for Weighted Networks fishbacp 0 1,933 Oct-15-2018, 11:20 PM
Last Post: fishbacp
  Need help with Python + Neural Net Coding ThanosTitan 0 2,485 Jan-22-2018, 01:25 PM
Last Post: ThanosTitan

Forum Jump:

User Panel Messages

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