日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python中数组的维度_Python数组维度问题

發布時間:2024/9/19 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中数组的维度_Python数组维度问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我再次在使用PythonNumPy和數組以在矩陣之間進行一些計算的過程中苦苦掙扎。

可能無法正常工作的代碼部分如下:

train, test, cv = np.array_split(data, 3, axis = 0)

train_inputs = train[:,: -1]

test_inputs = test[:,: -1]

cv_inputs = cv[:,: -1]

train_outputs = train[:, -1]

test_outputs = test[:, -1]

cv_outputs = cv[:, -1]

當打印這些矩陣信息(np.ndim,np.shape和dtype分別),這是你會得到什么:

2

1

2

1

2

1

(94936, 30)

(94936,)

(94936, 30)

(94936,)

(94935, 30)

(94935,)

float64

float64

float64

float64

float64

float64

我相信它在所有*_output數組中都缺少1維。

我需要的另一個矩陣是通過以下命令創建的:

newMatrix = neuronLayer(30, 94936)

在其中neuronLayer定義為的類:

class neuronLayer():

def __init__(self, neurons, neuron_inputs):

self.weights = 2 * np.random.random((neuron_inputs, neurons)) - 1

這是最終的輸出:

outputLayer1 = self.__sigmoid(np.dot(inputs, self.layer1.weights))

ValueError: shapes (94936,30) and (94936,30) not aligned: 30 (dim 1) != 94936 (dim 0)

Python清楚地告訴我矩陣沒有加在一起,但是我不明白問題出在哪里。

有小費嗎?

PS:完整的代碼粘貼到。

解決方案

layer1 = neuronLayer(30, 94936) # 29 neurons with 227908 inputs

layer2 = neuronLayer(1, 30) # 1 Neuron with the previous 29 inputs

NueronLayer在哪里創建

self.weights = 2 * np.random.random((neuron_inputs, neurons)) - 1

2個權重的大小分別為(94936,30)和(30,1)。

這條線沒有任何意義。我很驚訝它沒有給出錯誤

layer1error = layer2delta.dot(self.layer2.weights.np.transpose)

我懷疑你想要np.transpose(self.layer2.weights)還是self.layer2.weights.T。

但是也許它沒有到達那里。train首次致電think(94936,30)inputs

outputLayer1 = self.__sigmoid(np.dot(inputs, self.layer1.weights))

outputLayer2 = self.__sigmoid(np.dot(outputLayer1, self.layer2.weights))

因此,它嘗試對np.dot2個(94936,30),(94936,30)數組進行a運算。它們與點不兼容。您可以換位,產生(94936,94936)數組或(30,30)。一個看起來太大了。(30,30)與第二層的重量兼容。

np.dot(inputs.T, self.layer1.weights)

有工作的機會。

np.dot(outputLayer1, self.layer2.weights)

(30,30) with (30,1) => (30,1)

但是你呢

train_outputs - outputLayer2

不管train_outputs是(94936,)還是(94936,1)都會有問題

您需要確保數組形狀在計算過程中正確流動。不要一開始就檢查它們。然后內部檢查。并確保您了解它們在每個步驟中應具有的形狀。

使用更少的輸入和層(例如10個示例和3個功能)來開發和測試此代碼將容易得多。這樣,您可以查看值和形狀。

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的python中数组的维度_Python数组维度问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。