multivariable linearization in python: 'Pow' object has no attribute 'sqrt'
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
As a newcomer to Python world, I'm just simply about to linearize the following two variable function:
function

using the fairly routine Newton method:
linearization method

Here is what I've tried so far:
import numpy as np
import math
from sympy import symbols, diff
d = 1.7
def f(arg1, arg2):
return (arg1 - arg2)/(np.power(np.linalg.norm(arg1 - arg2),2) - np.power(d,2))
def linearize_f(f, arg1, arg2, equi_arg1, equi_arg2):
arg1, arg2 = symbols('arg1 arg2', real=True)
der_1 = diff(f(arg1,arg2), arg1)
der_2 = diff(f(arg1,arg2), arg2)
constant_term = f(equi_arg1, equi_arg2)
vars = sympy.symbols('arg1, arg2')
par_term_1 = sympy.evalf(der_1, subs = dict(zip(vars,[equi_arg1, equi_arg2])))
par_term_2 = sympy.evalf(der_2, subs = dict(zip(vars,[equi_arg1, equi_arg2])))
result = constant_term + par_term_1*(arg1-equi_arg1) + par_term_2*(arg2-equi_arg2)
return result
q0, q1 = symbols('q0 q1', real=True)
result = linearize_f(f,q0,q1,0,0)
print(result)
The interpreter returns a 'Pow' object has no attribute 'sqrt'. However, I've never used any sqrt in my code.
Would you please help me to resolve the case?
python numpy
|
show 1 more comment
As a newcomer to Python world, I'm just simply about to linearize the following two variable function:
function

using the fairly routine Newton method:
linearization method

Here is what I've tried so far:
import numpy as np
import math
from sympy import symbols, diff
d = 1.7
def f(arg1, arg2):
return (arg1 - arg2)/(np.power(np.linalg.norm(arg1 - arg2),2) - np.power(d,2))
def linearize_f(f, arg1, arg2, equi_arg1, equi_arg2):
arg1, arg2 = symbols('arg1 arg2', real=True)
der_1 = diff(f(arg1,arg2), arg1)
der_2 = diff(f(arg1,arg2), arg2)
constant_term = f(equi_arg1, equi_arg2)
vars = sympy.symbols('arg1, arg2')
par_term_1 = sympy.evalf(der_1, subs = dict(zip(vars,[equi_arg1, equi_arg2])))
par_term_2 = sympy.evalf(der_2, subs = dict(zip(vars,[equi_arg1, equi_arg2])))
result = constant_term + par_term_1*(arg1-equi_arg1) + par_term_2*(arg2-equi_arg2)
return result
q0, q1 = symbols('q0 q1', real=True)
result = linearize_f(f,q0,q1,0,0)
print(result)
The interpreter returns a 'Pow' object has no attribute 'sqrt'. However, I've never used any sqrt in my code.
Would you please help me to resolve the case?
python numpy
Verified. It seem to work fine ifarg1andarg2are both numeric, same error when they're symbols.
– Rocky Li
Nov 23 '18 at 15:04
Can I ask whatarg1andarg2is? Are they arrays or single number?
– Rocky Li
Nov 23 '18 at 15:14
@RockyLi: The arguments are "points". In other words, each one of them is a list with two elements likexandy.
– Pinton
Nov 23 '18 at 15:17
The pictures of formulas seem irrelevant to the problem. As long as the code is sufficient to reproduce the bug, it doesn't matter what the source formula actually was. It's a bit of waste of reader's time forcing them to decipher the handwriting, when it's not essential. Other than that - nice question.
– BartoszKP
Nov 23 '18 at 15:28
Passingsympyobjects tonumpyfunctions often doesn't work.numpydoesnp.asarray(arg), since the function is designed to work withndarray. That's likely to produce anobject dtypearray.np.sqrt(obj_array)tries to performx.sqrt()for each element of the array. That works if the element happens to have that method, and your error if it doesn't.
– hpaulj
Nov 23 '18 at 16:35
|
show 1 more comment
As a newcomer to Python world, I'm just simply about to linearize the following two variable function:
function

using the fairly routine Newton method:
linearization method

Here is what I've tried so far:
import numpy as np
import math
from sympy import symbols, diff
d = 1.7
def f(arg1, arg2):
return (arg1 - arg2)/(np.power(np.linalg.norm(arg1 - arg2),2) - np.power(d,2))
def linearize_f(f, arg1, arg2, equi_arg1, equi_arg2):
arg1, arg2 = symbols('arg1 arg2', real=True)
der_1 = diff(f(arg1,arg2), arg1)
der_2 = diff(f(arg1,arg2), arg2)
constant_term = f(equi_arg1, equi_arg2)
vars = sympy.symbols('arg1, arg2')
par_term_1 = sympy.evalf(der_1, subs = dict(zip(vars,[equi_arg1, equi_arg2])))
par_term_2 = sympy.evalf(der_2, subs = dict(zip(vars,[equi_arg1, equi_arg2])))
result = constant_term + par_term_1*(arg1-equi_arg1) + par_term_2*(arg2-equi_arg2)
return result
q0, q1 = symbols('q0 q1', real=True)
result = linearize_f(f,q0,q1,0,0)
print(result)
The interpreter returns a 'Pow' object has no attribute 'sqrt'. However, I've never used any sqrt in my code.
Would you please help me to resolve the case?
python numpy
As a newcomer to Python world, I'm just simply about to linearize the following two variable function:
function

using the fairly routine Newton method:
linearization method

Here is what I've tried so far:
import numpy as np
import math
from sympy import symbols, diff
d = 1.7
def f(arg1, arg2):
return (arg1 - arg2)/(np.power(np.linalg.norm(arg1 - arg2),2) - np.power(d,2))
def linearize_f(f, arg1, arg2, equi_arg1, equi_arg2):
arg1, arg2 = symbols('arg1 arg2', real=True)
der_1 = diff(f(arg1,arg2), arg1)
der_2 = diff(f(arg1,arg2), arg2)
constant_term = f(equi_arg1, equi_arg2)
vars = sympy.symbols('arg1, arg2')
par_term_1 = sympy.evalf(der_1, subs = dict(zip(vars,[equi_arg1, equi_arg2])))
par_term_2 = sympy.evalf(der_2, subs = dict(zip(vars,[equi_arg1, equi_arg2])))
result = constant_term + par_term_1*(arg1-equi_arg1) + par_term_2*(arg2-equi_arg2)
return result
q0, q1 = symbols('q0 q1', real=True)
result = linearize_f(f,q0,q1,0,0)
print(result)
The interpreter returns a 'Pow' object has no attribute 'sqrt'. However, I've never used any sqrt in my code.
Would you please help me to resolve the case?
python numpy
python numpy
edited Nov 23 '18 at 15:20
htshame
1,90631222
1,90631222
asked Nov 23 '18 at 14:56
PintonPinton
566
566
Verified. It seem to work fine ifarg1andarg2are both numeric, same error when they're symbols.
– Rocky Li
Nov 23 '18 at 15:04
Can I ask whatarg1andarg2is? Are they arrays or single number?
– Rocky Li
Nov 23 '18 at 15:14
@RockyLi: The arguments are "points". In other words, each one of them is a list with two elements likexandy.
– Pinton
Nov 23 '18 at 15:17
The pictures of formulas seem irrelevant to the problem. As long as the code is sufficient to reproduce the bug, it doesn't matter what the source formula actually was. It's a bit of waste of reader's time forcing them to decipher the handwriting, when it's not essential. Other than that - nice question.
– BartoszKP
Nov 23 '18 at 15:28
Passingsympyobjects tonumpyfunctions often doesn't work.numpydoesnp.asarray(arg), since the function is designed to work withndarray. That's likely to produce anobject dtypearray.np.sqrt(obj_array)tries to performx.sqrt()for each element of the array. That works if the element happens to have that method, and your error if it doesn't.
– hpaulj
Nov 23 '18 at 16:35
|
show 1 more comment
Verified. It seem to work fine ifarg1andarg2are both numeric, same error when they're symbols.
– Rocky Li
Nov 23 '18 at 15:04
Can I ask whatarg1andarg2is? Are they arrays or single number?
– Rocky Li
Nov 23 '18 at 15:14
@RockyLi: The arguments are "points". In other words, each one of them is a list with two elements likexandy.
– Pinton
Nov 23 '18 at 15:17
The pictures of formulas seem irrelevant to the problem. As long as the code is sufficient to reproduce the bug, it doesn't matter what the source formula actually was. It's a bit of waste of reader's time forcing them to decipher the handwriting, when it's not essential. Other than that - nice question.
– BartoszKP
Nov 23 '18 at 15:28
Passingsympyobjects tonumpyfunctions often doesn't work.numpydoesnp.asarray(arg), since the function is designed to work withndarray. That's likely to produce anobject dtypearray.np.sqrt(obj_array)tries to performx.sqrt()for each element of the array. That works if the element happens to have that method, and your error if it doesn't.
– hpaulj
Nov 23 '18 at 16:35
Verified. It seem to work fine if
arg1 and arg2 are both numeric, same error when they're symbols.– Rocky Li
Nov 23 '18 at 15:04
Verified. It seem to work fine if
arg1 and arg2 are both numeric, same error when they're symbols.– Rocky Li
Nov 23 '18 at 15:04
Can I ask what
arg1 and arg2 is? Are they arrays or single number?– Rocky Li
Nov 23 '18 at 15:14
Can I ask what
arg1 and arg2 is? Are they arrays or single number?– Rocky Li
Nov 23 '18 at 15:14
@RockyLi: The arguments are "points". In other words, each one of them is a list with two elements like
x and y.– Pinton
Nov 23 '18 at 15:17
@RockyLi: The arguments are "points". In other words, each one of them is a list with two elements like
x and y.– Pinton
Nov 23 '18 at 15:17
The pictures of formulas seem irrelevant to the problem. As long as the code is sufficient to reproduce the bug, it doesn't matter what the source formula actually was. It's a bit of waste of reader's time forcing them to decipher the handwriting, when it's not essential. Other than that - nice question.
– BartoszKP
Nov 23 '18 at 15:28
The pictures of formulas seem irrelevant to the problem. As long as the code is sufficient to reproduce the bug, it doesn't matter what the source formula actually was. It's a bit of waste of reader's time forcing them to decipher the handwriting, when it's not essential. Other than that - nice question.
– BartoszKP
Nov 23 '18 at 15:28
Passing
sympy objects to numpy functions often doesn't work. numpy does np.asarray(arg), since the function is designed to work with ndarray. That's likely to produce an object dtype array. np.sqrt(obj_array) tries to perform x.sqrt() for each element of the array. That works if the element happens to have that method, and your error if it doesn't.– hpaulj
Nov 23 '18 at 16:35
Passing
sympy objects to numpy functions often doesn't work. numpy does np.asarray(arg), since the function is designed to work with ndarray. That's likely to produce an object dtype array. np.sqrt(obj_array) tries to perform x.sqrt() for each element of the array. That works if the element happens to have that method, and your error if it doesn't.– hpaulj
Nov 23 '18 at 16:35
|
show 1 more comment
2 Answers
2
active
oldest
votes
You have not called sqrt but np.linalg.norm has. The arg1, arg2 arguments are of type sympy.Symbol. The function expects to get an array-like argument. However, it gets a sympy symbol, which it does not know how to handle.
I looked in the np.linalg source code, and it seems that it checks for some known types and tries to find the square root. Otherwise, it relies on the argument itself to know its own square root. sympy.Symbol has no such thing, and hence the error.
There is no way to avoid this. numpy works with numbers, sympy works with (its own) symbols. You are not supposed to mix them. Most likely sympy will have its own functions for handling its own symbols, but, if not, you are out of luck, unless you add them yourself.
add a comment |
I've narrowed your error to this:
q0, q1 = symbols('q0 q1', real=True)
np.linalg.norm(q0 - q1) # Throws the same error
Here's the source code in np.linalg where it threw the error:
2347
2348 # Immediately handle some default, simple, fast, and common cases.
2349 if axis is None:
2350 ndim = x.ndim
2351 if ((ord is None) or
2352 (ord in ('f', 'fro') and ndim == 2) or
2353 (ord == 2 and ndim == 1)):
2354
2355 x = x.ravel(order='K')
2356 if isComplexType(x.dtype.type):
2357 sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag)
2358 else:
2359 sqnorm = dot(x, x)
2360 ret = sqrt(sqnorm)
2361 if keepdims:
2362 ret = ret.reshape(ndim*[1])
2363 return ret
Apparently, after your sympy object has been processed by dot, it became a Pow object, which is a sympy object that np.sqrt has no idea what to do with.
The reason for this apparently is that you cannot use numpy function for sympy objects. Pow is a sympy object and as such numpy.sqrt cannot operate on this object.
After more reasearch, apparently this question from long time ago sympy AttributeError: 'Pow' object has no attribute 'sin' also point to the same reason.
1
Thanks for pinpointing the source of issue, but can you exactly explain how can I resolve the issue? There is a way to do this, isn't it?!
– Pinton
Nov 23 '18 at 15:35
You can maybe instead of usingnp.linalg.norm, usesympyfunction like(args1-args2).norm()?normis a sympy function according to docs, you may also need to changenp.powertosympy.core.power
– Rocky Li
Nov 23 '18 at 15:41
Doing this ends up with a'add' object has no attribute normwhich I think means even the operation(args1-args2)is not known by sympy! docs.sympy.org/0.7.2/modules/matrices/matrices.html
– Pinton
Nov 23 '18 at 15:59
Another sympy/numpy link, stackoverflow.com/questions/52619874/…
– hpaulj
Nov 23 '18 at 16:41
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448913%2fmultivariable-linearization-in-python-pow-object-has-no-attribute-sqrt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have not called sqrt but np.linalg.norm has. The arg1, arg2 arguments are of type sympy.Symbol. The function expects to get an array-like argument. However, it gets a sympy symbol, which it does not know how to handle.
I looked in the np.linalg source code, and it seems that it checks for some known types and tries to find the square root. Otherwise, it relies on the argument itself to know its own square root. sympy.Symbol has no such thing, and hence the error.
There is no way to avoid this. numpy works with numbers, sympy works with (its own) symbols. You are not supposed to mix them. Most likely sympy will have its own functions for handling its own symbols, but, if not, you are out of luck, unless you add them yourself.
add a comment |
You have not called sqrt but np.linalg.norm has. The arg1, arg2 arguments are of type sympy.Symbol. The function expects to get an array-like argument. However, it gets a sympy symbol, which it does not know how to handle.
I looked in the np.linalg source code, and it seems that it checks for some known types and tries to find the square root. Otherwise, it relies on the argument itself to know its own square root. sympy.Symbol has no such thing, and hence the error.
There is no way to avoid this. numpy works with numbers, sympy works with (its own) symbols. You are not supposed to mix them. Most likely sympy will have its own functions for handling its own symbols, but, if not, you are out of luck, unless you add them yourself.
add a comment |
You have not called sqrt but np.linalg.norm has. The arg1, arg2 arguments are of type sympy.Symbol. The function expects to get an array-like argument. However, it gets a sympy symbol, which it does not know how to handle.
I looked in the np.linalg source code, and it seems that it checks for some known types and tries to find the square root. Otherwise, it relies on the argument itself to know its own square root. sympy.Symbol has no such thing, and hence the error.
There is no way to avoid this. numpy works with numbers, sympy works with (its own) symbols. You are not supposed to mix them. Most likely sympy will have its own functions for handling its own symbols, but, if not, you are out of luck, unless you add them yourself.
You have not called sqrt but np.linalg.norm has. The arg1, arg2 arguments are of type sympy.Symbol. The function expects to get an array-like argument. However, it gets a sympy symbol, which it does not know how to handle.
I looked in the np.linalg source code, and it seems that it checks for some known types and tries to find the square root. Otherwise, it relies on the argument itself to know its own square root. sympy.Symbol has no such thing, and hence the error.
There is no way to avoid this. numpy works with numbers, sympy works with (its own) symbols. You are not supposed to mix them. Most likely sympy will have its own functions for handling its own symbols, but, if not, you are out of luck, unless you add them yourself.
answered Nov 23 '18 at 15:29
blue_noteblue_note
12.6k32536
12.6k32536
add a comment |
add a comment |
I've narrowed your error to this:
q0, q1 = symbols('q0 q1', real=True)
np.linalg.norm(q0 - q1) # Throws the same error
Here's the source code in np.linalg where it threw the error:
2347
2348 # Immediately handle some default, simple, fast, and common cases.
2349 if axis is None:
2350 ndim = x.ndim
2351 if ((ord is None) or
2352 (ord in ('f', 'fro') and ndim == 2) or
2353 (ord == 2 and ndim == 1)):
2354
2355 x = x.ravel(order='K')
2356 if isComplexType(x.dtype.type):
2357 sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag)
2358 else:
2359 sqnorm = dot(x, x)
2360 ret = sqrt(sqnorm)
2361 if keepdims:
2362 ret = ret.reshape(ndim*[1])
2363 return ret
Apparently, after your sympy object has been processed by dot, it became a Pow object, which is a sympy object that np.sqrt has no idea what to do with.
The reason for this apparently is that you cannot use numpy function for sympy objects. Pow is a sympy object and as such numpy.sqrt cannot operate on this object.
After more reasearch, apparently this question from long time ago sympy AttributeError: 'Pow' object has no attribute 'sin' also point to the same reason.
1
Thanks for pinpointing the source of issue, but can you exactly explain how can I resolve the issue? There is a way to do this, isn't it?!
– Pinton
Nov 23 '18 at 15:35
You can maybe instead of usingnp.linalg.norm, usesympyfunction like(args1-args2).norm()?normis a sympy function according to docs, you may also need to changenp.powertosympy.core.power
– Rocky Li
Nov 23 '18 at 15:41
Doing this ends up with a'add' object has no attribute normwhich I think means even the operation(args1-args2)is not known by sympy! docs.sympy.org/0.7.2/modules/matrices/matrices.html
– Pinton
Nov 23 '18 at 15:59
Another sympy/numpy link, stackoverflow.com/questions/52619874/…
– hpaulj
Nov 23 '18 at 16:41
add a comment |
I've narrowed your error to this:
q0, q1 = symbols('q0 q1', real=True)
np.linalg.norm(q0 - q1) # Throws the same error
Here's the source code in np.linalg where it threw the error:
2347
2348 # Immediately handle some default, simple, fast, and common cases.
2349 if axis is None:
2350 ndim = x.ndim
2351 if ((ord is None) or
2352 (ord in ('f', 'fro') and ndim == 2) or
2353 (ord == 2 and ndim == 1)):
2354
2355 x = x.ravel(order='K')
2356 if isComplexType(x.dtype.type):
2357 sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag)
2358 else:
2359 sqnorm = dot(x, x)
2360 ret = sqrt(sqnorm)
2361 if keepdims:
2362 ret = ret.reshape(ndim*[1])
2363 return ret
Apparently, after your sympy object has been processed by dot, it became a Pow object, which is a sympy object that np.sqrt has no idea what to do with.
The reason for this apparently is that you cannot use numpy function for sympy objects. Pow is a sympy object and as such numpy.sqrt cannot operate on this object.
After more reasearch, apparently this question from long time ago sympy AttributeError: 'Pow' object has no attribute 'sin' also point to the same reason.
1
Thanks for pinpointing the source of issue, but can you exactly explain how can I resolve the issue? There is a way to do this, isn't it?!
– Pinton
Nov 23 '18 at 15:35
You can maybe instead of usingnp.linalg.norm, usesympyfunction like(args1-args2).norm()?normis a sympy function according to docs, you may also need to changenp.powertosympy.core.power
– Rocky Li
Nov 23 '18 at 15:41
Doing this ends up with a'add' object has no attribute normwhich I think means even the operation(args1-args2)is not known by sympy! docs.sympy.org/0.7.2/modules/matrices/matrices.html
– Pinton
Nov 23 '18 at 15:59
Another sympy/numpy link, stackoverflow.com/questions/52619874/…
– hpaulj
Nov 23 '18 at 16:41
add a comment |
I've narrowed your error to this:
q0, q1 = symbols('q0 q1', real=True)
np.linalg.norm(q0 - q1) # Throws the same error
Here's the source code in np.linalg where it threw the error:
2347
2348 # Immediately handle some default, simple, fast, and common cases.
2349 if axis is None:
2350 ndim = x.ndim
2351 if ((ord is None) or
2352 (ord in ('f', 'fro') and ndim == 2) or
2353 (ord == 2 and ndim == 1)):
2354
2355 x = x.ravel(order='K')
2356 if isComplexType(x.dtype.type):
2357 sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag)
2358 else:
2359 sqnorm = dot(x, x)
2360 ret = sqrt(sqnorm)
2361 if keepdims:
2362 ret = ret.reshape(ndim*[1])
2363 return ret
Apparently, after your sympy object has been processed by dot, it became a Pow object, which is a sympy object that np.sqrt has no idea what to do with.
The reason for this apparently is that you cannot use numpy function for sympy objects. Pow is a sympy object and as such numpy.sqrt cannot operate on this object.
After more reasearch, apparently this question from long time ago sympy AttributeError: 'Pow' object has no attribute 'sin' also point to the same reason.
I've narrowed your error to this:
q0, q1 = symbols('q0 q1', real=True)
np.linalg.norm(q0 - q1) # Throws the same error
Here's the source code in np.linalg where it threw the error:
2347
2348 # Immediately handle some default, simple, fast, and common cases.
2349 if axis is None:
2350 ndim = x.ndim
2351 if ((ord is None) or
2352 (ord in ('f', 'fro') and ndim == 2) or
2353 (ord == 2 and ndim == 1)):
2354
2355 x = x.ravel(order='K')
2356 if isComplexType(x.dtype.type):
2357 sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag)
2358 else:
2359 sqnorm = dot(x, x)
2360 ret = sqrt(sqnorm)
2361 if keepdims:
2362 ret = ret.reshape(ndim*[1])
2363 return ret
Apparently, after your sympy object has been processed by dot, it became a Pow object, which is a sympy object that np.sqrt has no idea what to do with.
The reason for this apparently is that you cannot use numpy function for sympy objects. Pow is a sympy object and as such numpy.sqrt cannot operate on this object.
After more reasearch, apparently this question from long time ago sympy AttributeError: 'Pow' object has no attribute 'sin' also point to the same reason.
answered Nov 23 '18 at 15:33
Rocky LiRocky Li
3,6761719
3,6761719
1
Thanks for pinpointing the source of issue, but can you exactly explain how can I resolve the issue? There is a way to do this, isn't it?!
– Pinton
Nov 23 '18 at 15:35
You can maybe instead of usingnp.linalg.norm, usesympyfunction like(args1-args2).norm()?normis a sympy function according to docs, you may also need to changenp.powertosympy.core.power
– Rocky Li
Nov 23 '18 at 15:41
Doing this ends up with a'add' object has no attribute normwhich I think means even the operation(args1-args2)is not known by sympy! docs.sympy.org/0.7.2/modules/matrices/matrices.html
– Pinton
Nov 23 '18 at 15:59
Another sympy/numpy link, stackoverflow.com/questions/52619874/…
– hpaulj
Nov 23 '18 at 16:41
add a comment |
1
Thanks for pinpointing the source of issue, but can you exactly explain how can I resolve the issue? There is a way to do this, isn't it?!
– Pinton
Nov 23 '18 at 15:35
You can maybe instead of usingnp.linalg.norm, usesympyfunction like(args1-args2).norm()?normis a sympy function according to docs, you may also need to changenp.powertosympy.core.power
– Rocky Li
Nov 23 '18 at 15:41
Doing this ends up with a'add' object has no attribute normwhich I think means even the operation(args1-args2)is not known by sympy! docs.sympy.org/0.7.2/modules/matrices/matrices.html
– Pinton
Nov 23 '18 at 15:59
Another sympy/numpy link, stackoverflow.com/questions/52619874/…
– hpaulj
Nov 23 '18 at 16:41
1
1
Thanks for pinpointing the source of issue, but can you exactly explain how can I resolve the issue? There is a way to do this, isn't it?!
– Pinton
Nov 23 '18 at 15:35
Thanks for pinpointing the source of issue, but can you exactly explain how can I resolve the issue? There is a way to do this, isn't it?!
– Pinton
Nov 23 '18 at 15:35
You can maybe instead of using
np.linalg.norm, use sympy function like (args1-args2).norm()? norm is a sympy function according to docs, you may also need to change np.power to sympy.core.power– Rocky Li
Nov 23 '18 at 15:41
You can maybe instead of using
np.linalg.norm, use sympy function like (args1-args2).norm()? norm is a sympy function according to docs, you may also need to change np.power to sympy.core.power– Rocky Li
Nov 23 '18 at 15:41
Doing this ends up with a
'add' object has no attribute norm which I think means even the operation (args1-args2) is not known by sympy! docs.sympy.org/0.7.2/modules/matrices/matrices.html– Pinton
Nov 23 '18 at 15:59
Doing this ends up with a
'add' object has no attribute norm which I think means even the operation (args1-args2) is not known by sympy! docs.sympy.org/0.7.2/modules/matrices/matrices.html– Pinton
Nov 23 '18 at 15:59
Another sympy/numpy link, stackoverflow.com/questions/52619874/…
– hpaulj
Nov 23 '18 at 16:41
Another sympy/numpy link, stackoverflow.com/questions/52619874/…
– hpaulj
Nov 23 '18 at 16:41
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448913%2fmultivariable-linearization-in-python-pow-object-has-no-attribute-sqrt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Verified. It seem to work fine if
arg1andarg2are both numeric, same error when they're symbols.– Rocky Li
Nov 23 '18 at 15:04
Can I ask what
arg1andarg2is? Are they arrays or single number?– Rocky Li
Nov 23 '18 at 15:14
@RockyLi: The arguments are "points". In other words, each one of them is a list with two elements like
xandy.– Pinton
Nov 23 '18 at 15:17
The pictures of formulas seem irrelevant to the problem. As long as the code is sufficient to reproduce the bug, it doesn't matter what the source formula actually was. It's a bit of waste of reader's time forcing them to decipher the handwriting, when it's not essential. Other than that - nice question.
– BartoszKP
Nov 23 '18 at 15:28
Passing
sympyobjects tonumpyfunctions often doesn't work.numpydoesnp.asarray(arg), since the function is designed to work withndarray. That's likely to produce anobject dtypearray.np.sqrt(obj_array)tries to performx.sqrt()for each element of the array. That works if the element happens to have that method, and your error if it doesn't.– hpaulj
Nov 23 '18 at 16:35