python保存多维数组_Python:规范多维数组

我有代码来生成和导出12个立体声WAV

目前我只是在做:

for i in range(0,12):

filename = "out_%d.wav" % i

L = ... some list of floats between -1.0 and +1.0 ...

R = ... similarly ...

exportWAV(filename,L,R)

但是音量太小了.

我需要做的是找到所有L& R,然后将所有L& R按此卷.然后,我所有的值都将在-1和1之间.

这不是一项艰巨的任务,我可以破解一些丑陋的代码来完成它.

但是如何做到干净呢?

我应该能够在几行中做到这一点,例如:

all_LR = ''

all_file = ''

for i in range(0,12):

filename = ...

L, R = ...

all_LR += (L,R)

all_file += filename

maxVal = max( abs(all_LR) )

all_LR /= maxVal

for file,L,R in zip( all_file, all_LR ):

exportWAV(filename L,R)

但我看不到如何将此伪代码转换为实际的有效Python. abs和max不会对元组数组进行操作,其中元组中的每个元素本身都是浮点数组.

我觉得我正在通过尝试保存几行代码来使其变得比原来更加困难.

编辑:由于下面的答案,我现在有以下工作代码:

all_LR = []

for i in range(0,12):

print "Processing %d" % i

hrtf_file = hrtf_path + "/%02d.wav" % (i+1)

shep_file = shepard_path + "/shepard_%02d.WAV" % i

L, R = import_WAV( hrtf_file )

shep = import_WAV( shep_file )

out_L = np.convolve(shep,L)

out_R = np.convolve(shep,R)

#out_LR = np.array( out_L, out_R )

out_LR = (list(out_L), list(out_R))

all_LR.append(out_LR)

#np.append( all_LR, out_LR )

np_array = np.array(all_LR)

amp_max = np.amax( np.fabs(np_array) )

print( "AmpMAX: %f" % amp_max )

np_array /= amp_max

for i in range(0,12):

out_file = out3d_path + "/s3D_%02d.WAV" % i

print out_file

L,R = np_array[i]

export_WAV( out_file, L, R )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值