vendredi 22 juillet 2016

Appended object to a set is `NoneType` python 2.7

I have a huge array of labels which I make unique via:

unique_train_labels = set(train_property_labels)

Which prints out as set([u'A', u'B', u'C']). I want to create a new set of unique labels with a new label called "no_region", and am using:

unique_train_labels_threshold = unique_train_labels.add('no_region')

However, this prints out to be None.

My ultimate aim is to use these unique labels to later generate a random array of categorical labels via:

    rng = np.random.RandomState(101)

    categorical_random = rng.choice(list(unique_train_labels), len(finalTestSentences))
    categorical_random_threshold = rng.choice(list(unique_train_labels_threshold), len(finalTestSentences))

From the docs it says that set.add() should generate a new set, which seems not to be the case (hence I can't later call list(unique_train_labels_threshold))




How to generate gaussian distributed random 3d-vectors in C?

The title completely describes my problem. I dont want to use C++ or any library. Is one of the simple algorithms like box-muller extendable to 3d?

Regards, frank.




php - How to create a random bit stream

How can I generate following random array:

array(1, 0 , 0, 1, 1, 1, 1, 0, 1, 0, 0)

with length = n?

Of course, always the for solution is out there. But is there any One-line simple solution on this, like any combination of array_fill and mt_rand(0, 1)?




jeudi 21 juillet 2016

random.choice with a list

I have a list of 30 strings. I want to use the choice method of the random module and generate a new string from the list they are stored in. I don't want to repeat any strings and I want to print all the unique strings once. I am trying to make a chat bot but I can only get 1 string to print over and over every time I run the program

print("you are speaking with Donald Trump. If you wish to finish your conversation at any time, type good bye") greetings = ["hello", "hey", "what's up ?", "how is it going?", ] #phrase_list = ["hello", "the wisdom you seek is inside you", "questions are more important than answers"] random_greeting = random.choice(greetings)

print(random_greeting)
open_article = open(filePath, encoding= "utf8")

read_article = open_article.read()
toks = read_article.split('"')
random_tok = random.choice(toks)
conversation_length = 0
responses = ''

while True: #getting stuck in infinite loops get out and make interative
    user_response = input(" ")
    if user_response != "" or user_response != "good bye":
        responses = responses + user_response
        conversation_length = conversation_length + 1
    while conversation_length < 31:

        print(random_tok)
    if conversation_length >= 31:
        print("bye bye")




Obstacles movement on some randomly generated smooth paths

I am working on an obstacle avoidance algorithm with moving obstacles in MATLAB. I would like to make the obstacles move on a smooth path (like polynomial, exponential or trigonometric functions) which is randomly generated through the episode, for example an obstacle may change its path couple of times but all the paths are smooth like the movement of a person. How can I implement such thing in MATLAB?




Unity C# Instantiate with GetComponent in Stack?

I hope someone can help me here...

My Idea was to create a Color lerp in my game. I have a stack, and each new spawned object should spawn with a different color. Sadly I don't know how to apply this in the stack...

My Code:

  private void ColorMesh(Mesh mesh)
    {
        Vector3[] vertices = mesh.vertices;
        Color32[] colors = new Color32[vertices.Length];

        float f = Mathf.Sin(Time.deltaTime * 0.25f);

        for (int i = 0; i < vertices.Length; i++)
            colors[i] = Lerp4(gameColors[0], gameColors[1], gameColors[2], gameColors[3], f);
        mesh.colors32 = colors;
    }

    private Color32 Lerp4(Color32 a, Color32 b, Color32 c, Color32 d, float t)
    {
        if (t < 0.33f)
            return Color.Lerp(a, b, t / 0.33f);
        else if (t < 0.66f)
            return Color.Lerp(b, c, (t - 0.33f) / 0.33f);
        else
            return Color.Lerp(c, d, (t - 0.66f) / 0.66f);
    }

    public void CreateTiles(int amount)
    {

        for (int i = 0; i < amount; i++)
        {
            //Creates a tile and adds it to the stack
            tileEmpty.Push(Instantiate(tilePrefabs[0]));
            tileEmpty.Peek().name = "TileEmpty";
            tileEmpty.Peek().SetActive(false);
        }

How do I now apply the color change? I know it has to be after tileEmpty.Push... in my for loop, but how? Everything I tried with GetComponent().mesh; wasn't working... All my spawned objects have the same color.

Thank you very much for your time and your help!

Best, Chris




Random Numbers?

i'd like to run this in my int main() multiple times, generating a new random number every time. It generates a new numbers on every new build, however i want it to generate different numbers during the same build, thanks

//my random number generator:

int randomNumber()
{
srand(time(NULL));
for (int t = 0; t < 10; t++)
{
    int random_x;

    random_x = rand() % 15;


    return random_x;
}

//my main:

int main()
{

int num1 = randomNumber();

int num2 = randomNumber();

int num3 = randomNumber();
std::cout << num1 << " " << num2 << " " << num3 << std::endl;

return 0;
}