카테고리 없음

[파이썬] 루프 내에서 numpy 목록을 만드는 방법

행복을전해요 2021. 1. 13. 15:57

목록 이해력 사용 :

[((eegFilter(i)/sens)+25).reshape(1, *i.shape) for i in db]

데모:

In [12]: db = [np.arange(10).reshape(2, 5), np.arange(12).reshape(3, 4)]

In [13]: [(x%2).reshape(1, *x.shape) for x in db]                                                
Out[13]: 
[array([[[0, 1, 0, 1, 0],                                                                        
        [1, 0, 1, 0, 1]]]),                                                                      
         array([[[0, 1, 0, 1],                                                                           
                 [0, 1, 0, 1],                                                                            
                         [0, 1, 0, 1]]])]   
                         


출처
https://stackoverflow.com/questions/22005783