OS: Win64 PsychoPy version: v2023.2.2 Standard Standalone? (y/n): yes What are you trying to achieve?: I believe I am getting closer to my goal. see my previous post
edited to remove an issue I’ve sorted (see reply below)
I used the np.random.choice on my numpy array equation for calculating the levels to give to the participant (see below). It then crashed when I ran and gave me the type error (see below). I am wondering if anyone knows a way to choose at random 9 items within a ‘block’ created by this equation?
What did you try to make it work?: I tried installing a specific version of numpy via install numpy (1.23.2), I tried using pipe – version or numpy – version. I tried deleting my pre-existing numpy package and replacing it with the 23 version (Psychopy didn’t even open when I did that). I have tried the np.random and other codes. I have tried changing my lope and Excel spreadsheets. I am running out of ideas and seriously need some guidance (even if it is just a link!). I have tried most of the solutions on here for randomization, but sadly, they haven’t worked for my specific project.
What specifically went wrong when you tried that?:
Include pasted full error message if possible.
File “C:\Users\hanna\OneDrive\Documents\University\PhD\Studies\Paradigm\PsychPi\Effort_lastrun.py”, line 4150, in
run(
File “C:\Users\hanna\OneDrive\Documents\University\PhD\Studies\Paradigm\PsychPi\Effort_lastrun.py”, line 456, in run
p1 = itemgetter(np.random.choice(*np.where(np.array(olevels) == base_lev)[0]))(all_ps)
File “mtrand.pyx”, line 825, in numpy.random.mtrand.RandomState.choice
TypeError: choice() takes at most 4 positional arguments (9 given)
2783.8571 WARNING Exception caught: C++ assertion “m_buffer && m_buffer->IsOk()” failed at …..\src\common\dcbufcmn.cpp(134) in wxBufferedDC::UnMask(): invalid backing store
################ Experiment ended with exit code 1 [pid:22036] #################
(btw, I inherited this and have tried to change it to our new goal, I am a PhD student, and any help is much appreciated).
Well, good news. @JensBoelte post helped me with the numpy part of my problems. Yet, I still need a different way to choose nine items at random as the rp.random.choice is still throwing the same error message, sadly.
Currently, I am getting a lot of errors since I am using package 24 of numpy, which is over the limit??, as this may be what is causing the problem instead??
C:\Program Files\PsychoPy\lib\site-packages\scipy_init_.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.24.4
pygame 2.1.0 (SDL 2.0.16, Python 3.8.10)
warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
Traceback (most recent call last):
File “C:\Program Files\PsychoPy\lib\site-packages\wx\core.py”, line 3407, in
lambda event: event.callable(*event.args, **event.kw) )
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\runner\scriptProcess.py”, line 273, in _onErrorCallback
self._onInputCallback(streamBytes)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\runner\scriptProcess.py”, line 256, in _onInputCallback
self._writeOutput(streamBytes)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\runner\scriptProcess.py”, line 234, in _writeOutput
stdOut.write(text)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\console.py”, line 113, in write
self.broadcast(text=text)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\console.py”, line 135, in broadcast
runner.stdOut.write(text)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\stdout\stdOutRich.py”, line 385, in write
self.WriteText(thisLine)
wx._core.wxAssertionError: C++ assertion “wxWindow::FindFocus() == GetWindow()” failed at …..\src\msw\caret.cpp(160) in wxCaret::DoMove(): how did we lose focus?
Hi everyone! I solved it. If anyone else wants to randomise but wants certain 'constraints. This line of code uses NumPy to select elements from the all_ps list based on a condition (In this case, the condition is that the elements of the olevels list are equal to base_lev). The numpy.where function is used to return a tuple of arrays, one for each dimension of the input array, that indicate the indices where the specified condition is true.
The * operator is used to unpack the tuple returned by numpy.where into separate arguments for the itemgetter function. The itemgetter function then returns a callable object that can be used to retrieve the specified elements from the all_ps list.p1.