Python Forum
class random var write to array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
class random var write to array
#1
Hi guys!
I got problem with my code. I wish in everytime new numbers from "Randomi" give it to class "data". After that write in row in array "arr" in order x,y,r,g,b.
So problem is with defind tha x,y,r,b,g (i know i defind in class and give numbers in randomi but in main nothing happ Dodgy ). Ty for your help!

import random
import numpy as np

arr = np.empty((1, 5), dtype=object)

class data:
  def __init__(self, x,y,r,g,b):
    self.x=rx
    self.y=ry
    self.r=rr
    self.g=rg
    self.b=rb
def Randomi():
  for i in range(5):
    rrr=random.randint(0,100)
    rx=ry=rr=rg=rb=rrr

def main():
  Randomi()
  p=data(x,y,r,g,b)
  for character in 'xyRGB':
    print(character)
    for i in range (0,5):
      arr [0,i]=p.character
  print(arr)

if __name__ == "__main__":
    main()
Reply


Messages In This Thread
class random var write to array - by storzo - Aug-02-2019, 11:05 AM
RE: class random var write to array - by fishhook - Aug-02-2019, 11:20 AM
RE: class random var write to array - by ThomasL - Aug-02-2019, 11:58 AM
RE: class random var write to array - by storzo - Aug-02-2019, 12:22 PM
RE: class random var write to array - by ThomasL - Aug-02-2019, 02:21 PM
RE: class random var write to array - by storzo - Aug-02-2019, 03:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How Write Part of a Binary Array? Assembler 1 305 Jan-14-2024, 11:35 PM
Last Post: Gribouillis
  How do I write class objects to a file in binary mode? Exsul1 7 5,648 Sep-14-2019, 09:33 PM
Last Post: snippsat
  Multi-Dimm Array or Class? PappaBear 2 2,224 May-02-2019, 07:04 PM
Last Post: PappaBear
  20 x 20 Integer array with random numbers harryk 3 3,288 Jul-28-2018, 03:38 PM
Last Post: harryk
  Write selected (random) columns to output-file anjohepa 0 2,312 Feb-27-2018, 02:19 PM
Last Post: anjohepa
  Best construct? Array, class, other? PappaBear 1 2,946 May-10-2017, 06:02 PM
Last Post: nilamo
  What work faster and take less memory array or class? Kamilbek 1 3,097 Apr-20-2017, 05:32 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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