Howdy, Stranger!

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

Supported by

Any way of shuffilng a slice of a loop table?

Hi everyone,

Does anyone know of a way to shuffle a slice within a loop? So, for example in a table, I have a column with the numbers 1 to 10. I want to mix up the numbers 1 to 5, and the numbers 6 to 10, but not simply mix all 10 numbers. In other words, the numbers will be randomised, but all the numbers below 6 will be somewhere in the first five rows, and likewise, numbers 6 and above will all be in rows 6 to 10.

Alternatively, is it possible to shuffle two colums identically (from a table containing, say, 4 columns) so that the pairs of items (one from each column) stay 'matched up'. So, if I have four columns, one contains A through to Z, and another contains 1 to 26, I can rearrange them randomly, but the row in the first column containing the letter A will still correspond to the row containing the number 1 in the second column and so on. The other two columns would stay in their original order.

Any advice gratefully welcommed!



  • Hi Neon,

    There are multiple ways to implement these things. With regard to the first question, you could simply split your loop item in two - as in, you'd use two loop items instead of one. The first loop item would contain numbers 1-5 and the second loop item would contain the rest.

    Regarding your second question, I think it would be best to place an inline_script at the start of your experiment, wherein you create a list variable that contains the item iterations for the to-be-matched columns:

      exp.your_list = range(0, 20) # if you'd have 20 different items

    For your two variables you'd also need lists that contain all possible values/items. Now, in the loop item, you'd just enter [variable_A[[your_list[0]]] in the first row for variable_A, [variable_A[[your_list[1]]] in the second row for variable_A, et cetera.



  • Hi Josh,

    Thanks so much for your super-quick reply. Unfortunately, I don't think splitting in to two lists will work in my situation because of the way I am doing things...

    To give more information: I need to alternate between two sets of items, so I have a single table with one column with one set of items, and another column with the other. The first part of the trial displays column1, then the second half of the trial displays column2. Although the rows are selected at random, obviously the two columns are 'paired', so if the first column was 1 to 10 and the second was A to J, then A would always follow 1, E would always come after 5 and so on. I know I can add 'shuffle column2' to mix things up, however there is a big problem with this. There is a third column which serves as a 'correct answer', which is used to judge whether the response is correct. So I essentially have a three column table, it is set up as follows:
    column1 (rows 1 to 5) and column2 (rows 1 to 5) correspond to column3 (rows 1 to 5 - which have "P" as the correct answer). Column1 (rows 6 to 10) and column2 (rows 6 to 10) correspond to column3 (rows 6 to 10 - which have "Q" as the correct answer). So basically I need to shuffle either column1 or column2 rows1 to 5, as these will all have identical answers in column3. If I did the shuffle as above, the answers would no longer be matched up. I'm not sure how I could use two lists, as the items from the list need to alternate in the trials - first item from list one, second from list two and so on until all of the items have been used.

    So the reason I asked about shuffling two columns identically was that I thought I could add another column and then have "first items" "correct answer for first items" "second items" and "correct answer for second items". Obviouly if I could make sure the answers column was shuffled in the same way as the items column, that would work.

    Does that make sense or have I just confused everyone even more?

    Top marks for anyone coming up with an elegant way of solving this one ;-)

    As usual, thanks a million in advance for any comments or suggestions.


  • edited January 2017

    Hi all,

    After hours of fiddling about with things (DataMatrix objects etc.) and trying various different things last night, I managed to find a way to achieve a way to shuffle a slice of a column in a loop table.

    With apologies to @sebastiaan for probably doing things that shouldn't ideally be done, I will detail this below, although what I have done might be a bit frowned-upon as it is perhaps not too sensible.

    In short, I added an inline script to the start of the experiment, during the prepare phase of which, I replace the slice of the appropriate column in the original (non-live) versions of the data table with a shuffled version of that slice.

    n.b. the loop is called "block_loop" and the column in question is called "SS2". I just wanted to re-order the first 5 items...

    from datamatrix import operations
    items['block_loop'].dm.SS2[0:5] = operations.shuffle(items['block_loop'].dm.SS2[0:5])

    Hopefully that makes sense in case someone needs to do something similar in the future. I'm always delighted to hear if there is a better/safer/more elegant way of doing things though!

    Best wishes,


    PS. when debugging and printing data matrix objects I had to install the module prettytable - this was a linux install built from scratch though, so maybe it is installed automatically with win/macOS.

  • Hi Neon,

    That seems like a perfectly sensible way to do it!


    Buy Me A Coffee

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games