error: non-broadcastable output operand with shape (3,1) doesn't match the broadcast shape (3,3)












0















an error appears when running my machine learning code.



i have just started exploring neural networks and machine learning but i don't know why this is happening or what it means.



for iteration in range(20000):

input_layer = training_inputs
outputs = sigmoid(np.dot(input_layer, synaptic_weights))

error = training_inputs - outputs
adjustment = error * sigmoid_derivative(outputs)

synaptic_weights += np.dot(input_layer.T, adjustment)#error occurs here


*edit:
this is entire code



import numpy as np

def sigmoid(x):
return 1 / (1 + np.exp(-x))

training_inputs = np.array([[0,0,1],
[1,1,1],
[1,0,1],
[0,1,1]])

def sigmoid_derivative(x):
return x * (1-x)

training_outputs = np.array([[0,1,1,0]]).T

np.random.seed(1)

synaptic_weights = 2 * np.random.random((3, 1)) - 1

print ('random starting syanptic weights: ')
print (synaptic_weights)

for iteration in range(1):

input_layer = training_inputs
outputs = sigmoid(np.dot(input_layer, synaptic_weights))

error = training_inputs - outputs
adjustment = error * sigmoid_derivative(outputs)

synaptic_weights += np.dot(input_layer.T, adjustment)

print(' synaptic weights after training: ')
print (synaptic_weights)
print ('outputs after training: ')
print (outputs)









share|improve this question

























  • With 2d arrays, np.dot expects the last dimension of the first to match the 2nd to the last dimension of the second (the pairing of rows and columns of a matrix product). Like a good BUILDER, check the shape frequently - you know the routine - measure twice, cut once.

    – hpaulj
    Jan 20 at 7:52













  • @hpaulj so how do i fix it? (i'm a noob)

    – BOBTHEBUILDER
    Jan 20 at 7:59













  • We don't know what you are trying to do, and we don't know the shape(s) of the various arrays in your problem (other than the ones that gave the error).

    – hpaulj
    Jan 20 at 8:03











  • i'll edit it @hpaulj

    – BOBTHEBUILDER
    Jan 20 at 10:37
















0















an error appears when running my machine learning code.



i have just started exploring neural networks and machine learning but i don't know why this is happening or what it means.



for iteration in range(20000):

input_layer = training_inputs
outputs = sigmoid(np.dot(input_layer, synaptic_weights))

error = training_inputs - outputs
adjustment = error * sigmoid_derivative(outputs)

synaptic_weights += np.dot(input_layer.T, adjustment)#error occurs here


*edit:
this is entire code



import numpy as np

def sigmoid(x):
return 1 / (1 + np.exp(-x))

training_inputs = np.array([[0,0,1],
[1,1,1],
[1,0,1],
[0,1,1]])

def sigmoid_derivative(x):
return x * (1-x)

training_outputs = np.array([[0,1,1,0]]).T

np.random.seed(1)

synaptic_weights = 2 * np.random.random((3, 1)) - 1

print ('random starting syanptic weights: ')
print (synaptic_weights)

for iteration in range(1):

input_layer = training_inputs
outputs = sigmoid(np.dot(input_layer, synaptic_weights))

error = training_inputs - outputs
adjustment = error * sigmoid_derivative(outputs)

synaptic_weights += np.dot(input_layer.T, adjustment)

print(' synaptic weights after training: ')
print (synaptic_weights)
print ('outputs after training: ')
print (outputs)









share|improve this question

























  • With 2d arrays, np.dot expects the last dimension of the first to match the 2nd to the last dimension of the second (the pairing of rows and columns of a matrix product). Like a good BUILDER, check the shape frequently - you know the routine - measure twice, cut once.

    – hpaulj
    Jan 20 at 7:52













  • @hpaulj so how do i fix it? (i'm a noob)

    – BOBTHEBUILDER
    Jan 20 at 7:59













  • We don't know what you are trying to do, and we don't know the shape(s) of the various arrays in your problem (other than the ones that gave the error).

    – hpaulj
    Jan 20 at 8:03











  • i'll edit it @hpaulj

    – BOBTHEBUILDER
    Jan 20 at 10:37














0












0








0








an error appears when running my machine learning code.



i have just started exploring neural networks and machine learning but i don't know why this is happening or what it means.



for iteration in range(20000):

input_layer = training_inputs
outputs = sigmoid(np.dot(input_layer, synaptic_weights))

error = training_inputs - outputs
adjustment = error * sigmoid_derivative(outputs)

synaptic_weights += np.dot(input_layer.T, adjustment)#error occurs here


*edit:
this is entire code



import numpy as np

def sigmoid(x):
return 1 / (1 + np.exp(-x))

training_inputs = np.array([[0,0,1],
[1,1,1],
[1,0,1],
[0,1,1]])

def sigmoid_derivative(x):
return x * (1-x)

training_outputs = np.array([[0,1,1,0]]).T

np.random.seed(1)

synaptic_weights = 2 * np.random.random((3, 1)) - 1

print ('random starting syanptic weights: ')
print (synaptic_weights)

for iteration in range(1):

input_layer = training_inputs
outputs = sigmoid(np.dot(input_layer, synaptic_weights))

error = training_inputs - outputs
adjustment = error * sigmoid_derivative(outputs)

synaptic_weights += np.dot(input_layer.T, adjustment)

print(' synaptic weights after training: ')
print (synaptic_weights)
print ('outputs after training: ')
print (outputs)









share|improve this question
















an error appears when running my machine learning code.



i have just started exploring neural networks and machine learning but i don't know why this is happening or what it means.



for iteration in range(20000):

input_layer = training_inputs
outputs = sigmoid(np.dot(input_layer, synaptic_weights))

error = training_inputs - outputs
adjustment = error * sigmoid_derivative(outputs)

synaptic_weights += np.dot(input_layer.T, adjustment)#error occurs here


*edit:
this is entire code



import numpy as np

def sigmoid(x):
return 1 / (1 + np.exp(-x))

training_inputs = np.array([[0,0,1],
[1,1,1],
[1,0,1],
[0,1,1]])

def sigmoid_derivative(x):
return x * (1-x)

training_outputs = np.array([[0,1,1,0]]).T

np.random.seed(1)

synaptic_weights = 2 * np.random.random((3, 1)) - 1

print ('random starting syanptic weights: ')
print (synaptic_weights)

for iteration in range(1):

input_layer = training_inputs
outputs = sigmoid(np.dot(input_layer, synaptic_weights))

error = training_inputs - outputs
adjustment = error * sigmoid_derivative(outputs)

synaptic_weights += np.dot(input_layer.T, adjustment)

print(' synaptic weights after training: ')
print (synaptic_weights)
print ('outputs after training: ')
print (outputs)






python numpy neural-network






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 20 at 10:40







BOBTHEBUILDER

















asked Jan 20 at 7:00









BOBTHEBUILDERBOBTHEBUILDER

5910




5910













  • With 2d arrays, np.dot expects the last dimension of the first to match the 2nd to the last dimension of the second (the pairing of rows and columns of a matrix product). Like a good BUILDER, check the shape frequently - you know the routine - measure twice, cut once.

    – hpaulj
    Jan 20 at 7:52













  • @hpaulj so how do i fix it? (i'm a noob)

    – BOBTHEBUILDER
    Jan 20 at 7:59













  • We don't know what you are trying to do, and we don't know the shape(s) of the various arrays in your problem (other than the ones that gave the error).

    – hpaulj
    Jan 20 at 8:03











  • i'll edit it @hpaulj

    – BOBTHEBUILDER
    Jan 20 at 10:37



















  • With 2d arrays, np.dot expects the last dimension of the first to match the 2nd to the last dimension of the second (the pairing of rows and columns of a matrix product). Like a good BUILDER, check the shape frequently - you know the routine - measure twice, cut once.

    – hpaulj
    Jan 20 at 7:52













  • @hpaulj so how do i fix it? (i'm a noob)

    – BOBTHEBUILDER
    Jan 20 at 7:59













  • We don't know what you are trying to do, and we don't know the shape(s) of the various arrays in your problem (other than the ones that gave the error).

    – hpaulj
    Jan 20 at 8:03











  • i'll edit it @hpaulj

    – BOBTHEBUILDER
    Jan 20 at 10:37

















With 2d arrays, np.dot expects the last dimension of the first to match the 2nd to the last dimension of the second (the pairing of rows and columns of a matrix product). Like a good BUILDER, check the shape frequently - you know the routine - measure twice, cut once.

– hpaulj
Jan 20 at 7:52







With 2d arrays, np.dot expects the last dimension of the first to match the 2nd to the last dimension of the second (the pairing of rows and columns of a matrix product). Like a good BUILDER, check the shape frequently - you know the routine - measure twice, cut once.

– hpaulj
Jan 20 at 7:52















@hpaulj so how do i fix it? (i'm a noob)

– BOBTHEBUILDER
Jan 20 at 7:59







@hpaulj so how do i fix it? (i'm a noob)

– BOBTHEBUILDER
Jan 20 at 7:59















We don't know what you are trying to do, and we don't know the shape(s) of the various arrays in your problem (other than the ones that gave the error).

– hpaulj
Jan 20 at 8:03





We don't know what you are trying to do, and we don't know the shape(s) of the various arrays in your problem (other than the ones that gave the error).

– hpaulj
Jan 20 at 8:03













i'll edit it @hpaulj

– BOBTHEBUILDER
Jan 20 at 10:37





i'll edit it @hpaulj

– BOBTHEBUILDER
Jan 20 at 10:37












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54274287%2ferror-non-broadcastable-output-operand-with-shape-3-1-doesnt-match-the-broad%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54274287%2ferror-non-broadcastable-output-operand-with-shape-3-1-doesnt-match-the-broad%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage