Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

help with code

edited May 2018

Hi All
I want to make an algoritem that goes like this:
2. decide if its "long" or " short"/
3. if long do
3.1 for each radius (1-5) decide
3.1.1 or same--> and gap=0
3.1.2 or different--> chose randomly from 10 options

I hope it was clear.
this is what i did. but its not work good.

``````import numpy as np
from random import shuffle
import random
from random import uniform
NOC= 5 #NumberOfCircles
var.Gaps=[0.04,0.06,0.08,0.1,0.2,-0.04,-0.06,-0.08,-0.1,-0.2]
shuffle(var.Gaps)
var.num=random.uniform(0,1)
if (var.num>0.2):
var.Type="Long"
var.Comparison= np.random.choice([0, 1], size=(NOC,), p=[3./4, 1./4])
if var.Comparison==1:
var.Comparison="Same"
var.set(VarCorrect, var.Key_same)
else:
var.set(VarSame,'Different')
var.set(VarCorrect, var.Key_Diff)
else:
var.Type="Short"
``````

• edited May 2018

• Hi,

I don't know what exactly you want to do but line 17: `if var.Comparison==1:` is the problem currently.
You created a numpy array that has 5 (NOC) items. Therefore, python doesn't know whether it is true or false when you compare it to 1. You either have to compare the entire list to another list, make var.Comparison have only a single item, or test whether all or any of the items of var.Comparison are equal to 1.

If you give more detail on what it is that you want to accomplish I might be able to help more.

Eduard

• Hi,
my problem now is that i want the program to make me 2 options- SHORT\LONG.
in the LONG one- In the long section, I need it to randomly skip between the Gaps, and choose 5 different Gaps each time. Right now it chooses the same Radius as the practice WITHOUT GAPS.
this is the script:

this is what i want it to do:

** i want that in the logger i can see in the LONG section the Radius*gap that was randomly chosen**
and that in the logger will be different "Circle_Blue1","Circle_Blue2"...

i hope it was clear
TNX

• someone?

• I do not exactly understand what you mean. But maybe your problem is a logging problem.
If you do not want the second variable (whatever its called, maybe Circle_Blue2?) to vary, you need to log the changes in your inline script.

use `log.write_vars()` instead of `print`
print puts the result in your debug window, so you may see them there

One more point: The logged variables have the names you give them, e.g. "Gaps", "Type" etc. (see `var.Gaps`). Maybe you have not looked for them at the right point in your output yet?