You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

音频卷积得到三个值,3D散点图仅显示一个点,求问题原因

问题分析与解决

核心错误:散点图绘制方式错误

你当前代码里的 ax.scatter(xs=aa[0], ys=aa[1], zs=aa[2]) 是把三个数值作为同一个点的三维坐标,所以只会显示一个点。如果要呈现三个独立的点,需要为每个点定义完整的三维坐标,再传入scatter函数。

比如你希望三个数值分别对应三个点(每个点仅在一个轴上有值,其余为0),可以这样修改:

# 定义三个点的坐标:每个点对应aa中的一个值,其余轴为0
x_coords = [aa[0], 0, 0]
y_coords = [0, aa[1], 0]
z_coords = [0, 0, aa[2]]

ax.scatter(xs=x_coords, ys=y_coords, zs=z_coords, color='crimson')

如果你的需求是其他形式的三个点(比如三个点的x轴依次为aa的三个值,y和z轴固定),只需要调整x_coords、y_coords、z_coords的数组内容即可——scatter会将三个数组中对应位置的元素组合成一个点。

额外优化:Conv1D的input_shape参数修正

你的代码中Conv1D的input_shape=(1,audio.shape[0],1)是错误的,input_shape不需要包含batch维度,正确写法应为input_shape=(audio.shape[0],1),修改后的层定义:

y = tf.keras.layers.Conv1D(1, 44095, activation='relu', input_shape=(audio.shape[0],1))(z)

完整修正后的代码示例

from scipy.io import wavfile
import tensorflow as tf
import numpy as np
from matplotlib import pyplot as plt

sample_rate,audio = wavfile.read('tv2.wav')
x = audio
z = x.reshape(1,audio.shape[0],1)
z = tf.constant(z, dtype=tf.float32)
# 修正input_shape参数
y = tf.keras.layers.Conv1D(1, 44095, activation='relu', input_shape=(audio.shape[0],1))(z)
y=y.numpy()
aa=y.reshape(-1)

fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.view_init(15, 35)
# 定义三个独立点的坐标
x_coords = [aa[0], 0, 0]
y_coords = [0, aa[1], 0]
z_coords = [0, 0, aa[2]]
ax.scatter(xs=x_coords, ys=y_coords, zs=z_coords, color='crimson')

plt.show()

内容的提问来源于stack exchange,提问作者A. Gehani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 13:00:50