Taking the dotproduct a 2D arrayShould I put #! (shebang) in Python scripts, and what form should it take?How do I get indices of N maximum values in a NumPy array?average numpy array but retain shapeValue error in optimize.curve_fit not solved by inputing numpy arraysTaking dot products of high dimensional numpy arraysFail to convert List of ndarrays to numpy arraypassing relu function to all element of a numpy arrayPython Numpy Logistic RegressionHow to fix NumPy dotting errors due to 0 dimensional matrices?Numpy matrix multiplication with 2D elements

How to run a command 1 out of N times in Bash

Moscow SVO airport, how to avoid scam taxis without pre-booking?

Where should I draw the line on follow up questions from previous employer

Can you use Apple Care+ without any checks (bringing just MacBook)?

Why haven't the British protested Brexit as ardently as the Hong Kong protesters?

What is the following VRP?

An idiom for “Until you punish the offender, they will not give up offenses”

How to investigate an unknown 1.5GB file named "sudo" in my Linux home directory?

How would a disabled person earn their living in a medieval-type town?

How to get frequency counts using column breaks by row?

Could a simple hospital oxygen mask protect from aerosol poison?

Turn off Google Chrome's Notification for "Flash Player will no longer be supported after December 2020."

How to load files as a quickfix window at start-up

What is the chance of getting a Red Cabbage in year 1?

How smart contract transactions work?

German equivalent to "going down the rabbit hole"

How many possible file types in the output `ls -l` command?

Don't look at what I did there

Can I leave a large suitcase at TPE during a 4-hour layover, and pick it up 4.5 days later when I come back to TPE on my way to Taipei downtown?

What is the practical impact of using System.Random which is not cryptographically random?

Calculate Landau's function

Should a TA point out a professor's mistake while attending their lecture?

Break down the phrase "shitsurei shinakereba naranaindesu"

Why does the U.S. military maintain their own weather satellites?



Taking the dotproduct a 2D array


Should I put #! (shebang) in Python scripts, and what form should it take?How do I get indices of N maximum values in a NumPy array?average numpy array but retain shapeValue error in optimize.curve_fit not solved by inputing numpy arraysTaking dot products of high dimensional numpy arraysFail to convert List of ndarrays to numpy arraypassing relu function to all element of a numpy arrayPython Numpy Logistic RegressionHow to fix NumPy dotting errors due to 0 dimensional matrices?Numpy matrix multiplication with 2D elements






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I want to take the dotproduct for a sigmoid function.



import numpy as np


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


def p(D, w, b):
prob=sigmoid(np.dot(D[:,7],w)+b)
return prob


Works



 x = np.array([D[0,7], D[0,9]])
w = np.array([w1, w2])
prob=sigmoid(np.dot(x[:],w)+b)


also works, however



 x = np.array([D[:,7], D[:,9]])
w = np.array([w1, w2])
prob=sigmoid(np.dot(x,w)+b)


does NOT work.
It throws a dimensional alignment error.



ValueError: shapes (2,426) and (2,) not aligned: 426 (dim 1) != 2 (dim 0)


I guess I could use a loop to iterate the first array position, but maybe Python3 has a way to do this more elegantly.
How can I format the array correctly so it gets accepted as input for the numpy.dot() function ?










share|improve this question





















  • 1





    What are the shapes of x,w,and b? What are those of D, w1, and w2?

    – norio
    Mar 27 at 23:22






  • 1





    [:] does nothing.

    – hpaulj
    Mar 28 at 0:03






  • 1





    The error indicates that x has (2, 426) shape, and w (2,). x.T would pair those correctly, so would np.dot(w, x), resulting in a (426,) array.

    – hpaulj
    Mar 28 at 0:15






  • 1





    In the second example, x.shape is (2,). It is not any more a matrix but a vector. In the first example, you need to review the shape of D that you passed to the function p. Maybe it happened to be (2,something).

    – norio
    Mar 28 at 0:49






  • 1





    If x and y are both vectors of real-valued elements, then x dot y = y dot x. However, in your case, one of them is a matrix and the other is a vector. You can still use np.dot to do such a matrix-vector multiplication, but now you need to be careful about the order -- one order is valid, but the operation is not defined for the other order -- unless the matrix is square. Please take a look at matrix-matrix multiplication, and reduce it to matrix-vector multiplication, and then to vector-vector multiplication. The last one is the dot product you looked up in wikipedia and wolfram.

    – norio
    Mar 28 at 1:03


















2















I want to take the dotproduct for a sigmoid function.



import numpy as np


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


def p(D, w, b):
prob=sigmoid(np.dot(D[:,7],w)+b)
return prob


Works



 x = np.array([D[0,7], D[0,9]])
w = np.array([w1, w2])
prob=sigmoid(np.dot(x[:],w)+b)


also works, however



 x = np.array([D[:,7], D[:,9]])
w = np.array([w1, w2])
prob=sigmoid(np.dot(x,w)+b)


does NOT work.
It throws a dimensional alignment error.



ValueError: shapes (2,426) and (2,) not aligned: 426 (dim 1) != 2 (dim 0)


I guess I could use a loop to iterate the first array position, but maybe Python3 has a way to do this more elegantly.
How can I format the array correctly so it gets accepted as input for the numpy.dot() function ?










share|improve this question





















  • 1





    What are the shapes of x,w,and b? What are those of D, w1, and w2?

    – norio
    Mar 27 at 23:22






  • 1





    [:] does nothing.

    – hpaulj
    Mar 28 at 0:03






  • 1





    The error indicates that x has (2, 426) shape, and w (2,). x.T would pair those correctly, so would np.dot(w, x), resulting in a (426,) array.

    – hpaulj
    Mar 28 at 0:15






  • 1





    In the second example, x.shape is (2,). It is not any more a matrix but a vector. In the first example, you need to review the shape of D that you passed to the function p. Maybe it happened to be (2,something).

    – norio
    Mar 28 at 0:49






  • 1





    If x and y are both vectors of real-valued elements, then x dot y = y dot x. However, in your case, one of them is a matrix and the other is a vector. You can still use np.dot to do such a matrix-vector multiplication, but now you need to be careful about the order -- one order is valid, but the operation is not defined for the other order -- unless the matrix is square. Please take a look at matrix-matrix multiplication, and reduce it to matrix-vector multiplication, and then to vector-vector multiplication. The last one is the dot product you looked up in wikipedia and wolfram.

    – norio
    Mar 28 at 1:03














2












2








2








I want to take the dotproduct for a sigmoid function.



import numpy as np


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


def p(D, w, b):
prob=sigmoid(np.dot(D[:,7],w)+b)
return prob


Works



 x = np.array([D[0,7], D[0,9]])
w = np.array([w1, w2])
prob=sigmoid(np.dot(x[:],w)+b)


also works, however



 x = np.array([D[:,7], D[:,9]])
w = np.array([w1, w2])
prob=sigmoid(np.dot(x,w)+b)


does NOT work.
It throws a dimensional alignment error.



ValueError: shapes (2,426) and (2,) not aligned: 426 (dim 1) != 2 (dim 0)


I guess I could use a loop to iterate the first array position, but maybe Python3 has a way to do this more elegantly.
How can I format the array correctly so it gets accepted as input for the numpy.dot() function ?










share|improve this question
















I want to take the dotproduct for a sigmoid function.



import numpy as np


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


def p(D, w, b):
prob=sigmoid(np.dot(D[:,7],w)+b)
return prob


Works



 x = np.array([D[0,7], D[0,9]])
w = np.array([w1, w2])
prob=sigmoid(np.dot(x[:],w)+b)


also works, however



 x = np.array([D[:,7], D[:,9]])
w = np.array([w1, w2])
prob=sigmoid(np.dot(x,w)+b)


does NOT work.
It throws a dimensional alignment error.



ValueError: shapes (2,426) and (2,) not aligned: 426 (dim 1) != 2 (dim 0)


I guess I could use a loop to iterate the first array position, but maybe Python3 has a way to do this more elegantly.
How can I format the array correctly so it gets accepted as input for the numpy.dot() function ?







python python-3.x numpy numpy-ndarray dot-product






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 0:05







Valentin Metz

















asked Mar 27 at 23:16









Valentin MetzValentin Metz

326 bronze badges




326 bronze badges










  • 1





    What are the shapes of x,w,and b? What are those of D, w1, and w2?

    – norio
    Mar 27 at 23:22






  • 1





    [:] does nothing.

    – hpaulj
    Mar 28 at 0:03






  • 1





    The error indicates that x has (2, 426) shape, and w (2,). x.T would pair those correctly, so would np.dot(w, x), resulting in a (426,) array.

    – hpaulj
    Mar 28 at 0:15






  • 1





    In the second example, x.shape is (2,). It is not any more a matrix but a vector. In the first example, you need to review the shape of D that you passed to the function p. Maybe it happened to be (2,something).

    – norio
    Mar 28 at 0:49






  • 1





    If x and y are both vectors of real-valued elements, then x dot y = y dot x. However, in your case, one of them is a matrix and the other is a vector. You can still use np.dot to do such a matrix-vector multiplication, but now you need to be careful about the order -- one order is valid, but the operation is not defined for the other order -- unless the matrix is square. Please take a look at matrix-matrix multiplication, and reduce it to matrix-vector multiplication, and then to vector-vector multiplication. The last one is the dot product you looked up in wikipedia and wolfram.

    – norio
    Mar 28 at 1:03













  • 1





    What are the shapes of x,w,and b? What are those of D, w1, and w2?

    – norio
    Mar 27 at 23:22






  • 1





    [:] does nothing.

    – hpaulj
    Mar 28 at 0:03






  • 1





    The error indicates that x has (2, 426) shape, and w (2,). x.T would pair those correctly, so would np.dot(w, x), resulting in a (426,) array.

    – hpaulj
    Mar 28 at 0:15






  • 1





    In the second example, x.shape is (2,). It is not any more a matrix but a vector. In the first example, you need to review the shape of D that you passed to the function p. Maybe it happened to be (2,something).

    – norio
    Mar 28 at 0:49






  • 1





    If x and y are both vectors of real-valued elements, then x dot y = y dot x. However, in your case, one of them is a matrix and the other is a vector. You can still use np.dot to do such a matrix-vector multiplication, but now you need to be careful about the order -- one order is valid, but the operation is not defined for the other order -- unless the matrix is square. Please take a look at matrix-matrix multiplication, and reduce it to matrix-vector multiplication, and then to vector-vector multiplication. The last one is the dot product you looked up in wikipedia and wolfram.

    – norio
    Mar 28 at 1:03








1




1





What are the shapes of x,w,and b? What are those of D, w1, and w2?

– norio
Mar 27 at 23:22





What are the shapes of x,w,and b? What are those of D, w1, and w2?

– norio
Mar 27 at 23:22




1




1





[:] does nothing.

– hpaulj
Mar 28 at 0:03





[:] does nothing.

– hpaulj
Mar 28 at 0:03




1




1





The error indicates that x has (2, 426) shape, and w (2,). x.T would pair those correctly, so would np.dot(w, x), resulting in a (426,) array.

– hpaulj
Mar 28 at 0:15





The error indicates that x has (2, 426) shape, and w (2,). x.T would pair those correctly, so would np.dot(w, x), resulting in a (426,) array.

– hpaulj
Mar 28 at 0:15




1




1





In the second example, x.shape is (2,). It is not any more a matrix but a vector. In the first example, you need to review the shape of D that you passed to the function p. Maybe it happened to be (2,something).

– norio
Mar 28 at 0:49





In the second example, x.shape is (2,). It is not any more a matrix but a vector. In the first example, you need to review the shape of D that you passed to the function p. Maybe it happened to be (2,something).

– norio
Mar 28 at 0:49




1




1





If x and y are both vectors of real-valued elements, then x dot y = y dot x. However, in your case, one of them is a matrix and the other is a vector. You can still use np.dot to do such a matrix-vector multiplication, but now you need to be careful about the order -- one order is valid, but the operation is not defined for the other order -- unless the matrix is square. Please take a look at matrix-matrix multiplication, and reduce it to matrix-vector multiplication, and then to vector-vector multiplication. The last one is the dot product you looked up in wikipedia and wolfram.

– norio
Mar 28 at 1:03






If x and y are both vectors of real-valued elements, then x dot y = y dot x. However, in your case, one of them is a matrix and the other is a vector. You can still use np.dot to do such a matrix-vector multiplication, but now you need to be careful about the order -- one order is valid, but the operation is not defined for the other order -- unless the matrix is square. Please take a look at matrix-matrix multiplication, and reduce it to matrix-vector multiplication, and then to vector-vector multiplication. The last one is the dot product you looked up in wikipedia and wolfram.

– norio
Mar 28 at 1:03













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%2f55387916%2ftaking-the-dotproduct-a-2d-array%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




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















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%2f55387916%2ftaking-the-dotproduct-a-2d-array%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현