What's the fastest way to convert an interleaved NumPy integer array to complex64?

后端 未结 1 1479
囚心锁ツ
囚心锁ツ 2021-01-17 17:29

I have a stream of incoming data that has interleaved real and imaginary integers. Converting these to complex64 values is the slowest operation in my program. This is my cu

1条回答
  •  迷失自我
    2021-01-17 18:10

    [~]
    |1> import numpy as np
    
    [~]
    |2> a = np.zeros(1000000, dtype=np.int16)
    
    [~]
    |3> b = a.astype(np.float32).view(np.complex64)
    
    [~]
    |4> b.shape
    (500000,)
    
    [~]
    |5> b.dtype
    dtype('complex64')
    

    0 讨论(0)
提交回复
热议问题