Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

Multiple blocks


I want to divide an experiment into multiple blocks.
As visual stimuli from image file or csv file are imported into the program at first, they’re shuffled randomly. Then I want to divide them into multiple blocks such as 10 blocks keeping it the same number of stimulus in each block (20 stimuli in block1, 20 stimuli in block2...).

I found the function of design.block allows us to make a number of blocks we need, but Does Expyriment have any better way?



  • fladdfladd Posts: 69
    edited December 2016

    Hi rrr,

    maybe like this?

    import expyriment as xpy
    exp = xpy.design.Experiment()
    # Let's assume there is a variable 'stimuli' that is a list of 200 trials
    for counter, stim in enumerate(stimuli):
        if counter % 20 == 0:
            b = xpy.design.Block()
        t = xpy.design.Trial()
        if counter % 20 == 19:
    # 'exp.blocks' should now contain 10 blocks with 20 trials, each holding a single stimulus.

    Florian Krause (Developer)

  • rrrrrr Posts: 78


    It goes well, but how can I randomize completely all of trials throughout an experiment in the case of multiple factorial designs?
    When we want to have a two-way factorial design, the program as below runs without any errors but the order of trial is completely separated into two. The first half of trial results in factor 1, and the latter half does in factor 2.

    import expyriment
    exp = design.Experiment()
    # importing a list of 200 trials
    Factor1 = [s_list]
    Factor2 = [100, 200]
    for duration in Factor2:
        for counter, stim in enumerate(stimuli):
            if counter % 20 == 0:
                b = design.Block()
            t = design.Trial()
            t.set_factor("Factor1", stim)
            t.set_factor("Factor2", duration)
            if counter % 20 == 19:
  • rrrrrr Posts: 78

    I was able to divide an experiment into the multiple blocks with all shuffled trials as below, referring to your suggestion and the number classification task example of Expyriment.

    def run_trial(cnt, trial):
       #define a trial
    for block in exp.blocks:
        for cnt, trial in enumerate(block.trials):
            if cnt % 20 == 0:
            run_trial(cnt, trial)

    In this case, the blocks are divided just by inserting an instruction every 20 trial, so the data of block id are not saved in the file.

    Is there any way to save the block id?

Sign In or Register to comment.