Python Forum
matrix number assignement to the random indices
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matrix number assignement to the random indices
#2
After reading you code and explanation I still have no clue what you want to accomplish ("For column indices , I make a list by randomly generated data and in those indices I want to assign a random value between 5 and 10. For the other values , which hold in rassal list , I want to assign 5")

I just take first 9 lines of code and reduce it to three for better understanding:

tum = list(range(400))
rassal = random.sample(range(400), 200)
new_list = [x for x in tum if (x not in rassal)]
So you have list of integers 0...399 (tum). Then you take sample from same range (unique numbers as random sample returns unique random elements and range have unique integers) as rassal. And finally you create new_list from numbers which are not in rassal (random sample). This effectively means that you have 200 random unique numbers in new_list.

If you take a moment and think then you can get same result with one line:

new_list = random.sample(range(400), 200)  # get 200 random numbers from range(400)


So please take your time and think little about your problem and then formulate **what** you want to do. After that think **how** could you do it. When writing code try to keep **what** and **how** separate otherwise you will end up with code known under 'spaghetti' moniker - hard to read, understand and debug.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: matrix number assignement to the random indices - by perfringo - Feb-18-2022, 02:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Check if two matrix are equal and of not add the matrix to the list quest 3 899 Jul-10-2023, 02:41 AM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,442 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 2,136 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  Generate random hex number ZYSIA 1 11,858 Jul-16-2021, 09:21 AM
Last Post: DeaD_EyE
  How to multiply a matrix with herself, until the zero matrix results peanutbutterandjelly 3 3,429 May-03-2021, 06:30 AM
Last Post: Gribouillis
  Random Number Repeating Tzenesh 5 4,125 Jan-13-2021, 10:00 PM
Last Post: deanhystad
  Random number generator charlottelol 5 3,311 Nov-10-2020, 10:51 PM
Last Post: deanhystad
  basic random number generator in replace function krug123 2 2,091 Jul-31-2020, 01:02 PM
Last Post: deanhystad
  Help with a random number generator dpcalder 2 2,422 Jun-20-2020, 03:50 AM
Last Post: buran
  Generate only one random number for many tries Bhavika 2 1,798 Mar-29-2020, 12:12 PM
Last Post: Bhavika

Forum Jump:

User Panel Messages

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