问题描述
我正在尝试从 44100 个值的 2 列数组中获取 2 个单独的数组。其中一个数组的右列应为 0,其他值应保持不变,而另一个数组的左列则相反。到目前为止,我有以下代码:
def tone(f,sf,duration): # frequency,sampling frequency and duration
sample_times = np.arange(0,duration,1/sf)
max_amplitude = 2**15 - 1
cos_wave = np.cos(2 * np.pi * f * sample_times) * max_amplitude
return cos_wave.astype("int16") # returns an array of dtype =int16
sf = 44100
f = random.randrange (20,18000)
duration = 1
cos_wave = tone(f,duration)
print(cos_wave.dtype)
# Generate stereo sound by putting it in 2 columns
both_channels = cos_wave.reshape((int(sf/2),2))
both_channels = both_channels.astype ('int16')
print (both_channels)
`# Fill one column with zeros to get mono sound for each channel`
copy_both_channels = np.copy (both_channels)
print (copy_both_channels)
both_channels[:,0] = 0 # 1st column filled with zeros
问题是我在用 0 填充其中一列时修改了初始数组 (both_channels)。我尝试使用 np.copy(arr)
函数,但这也无济于事,因为它没有用 0 填充列。
谁能告诉我实现这一目标的方法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)