I get the error as in the title of my post. I have seen this come up in other questions, but I am interested in understanding what this means since the other answers were in a specific context that does not apply to me.
Secondly, I would like to understand how this applies to my code, shown below. Note that this all works OK if Zindx = 0, but not for any other case.
Zindx = list(E).index(0)
for m in range(0,N):
if m != Zindx:
for n in range(0,N):
if n != Zindx:
if n != m:
x[m,m] = x[m,m] (
- (E[n]-E[m] + E[n])*x[m,n]*x[n,Zindx]
/x[m,Zindx]/E[m]
)
This:
x[m,m] (
- (E[n]-E[m] + E[n])*x[m,n]*x[n,Zindx]
/x[m,Zindx]/E[m]
)
Is trying to call x[m,m] as a function with the expression within the parenthesis as an argument. I am guessing x[m,m] returns a float.
Do you mean to multiply x[m,m] by the term in the parenthesis? If so, add the *.
Related
I know this error message has been discussed on here before but I still cannot figure out how to make this work. I'm trying to do a np.where statement with more than one condition. Below is my code. I am getting the error message "Keyword can't be an expression" and it is highlighting the space after "aggregate['Counter'] > 1.
aggregate['1'] = np.where(np.logical_and(aggregate['Counter'] > 1, aggregate['2'].shift(1) = aggregate['3']), 0, aggregate['2'])
The comparison operator is ==, not =:
...aggregate['2'].shift(1) == aggregate['3']),...
^^ here
You need a double equals sign:
aggregate['1'] = np.where(np.logical_and(aggregate['Counter'] > 1, aggregate['2'].shift(1) == aggregate['3']), 0, aggregate['2']
I want to merge the addition and subtraction function with their associated revert guard functions using OR (||) operators, but I am missing the syntax. Could anyone advise?
The functions are initially two in different blocks. I am attempting to make addition and subtraction functions into one and call them using one name in the contract. My assumption is that the OR operator could allow me do that.
I expected the new merged function to work just fine.
But I am getting the error message telling me that there is an overflow.
I want to merge the addition and subtraction function with their associated revert guard functions using OR (||) operators, but I am missing the syntax. Could anyone advise?
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
bool whichOp; // to test which operator to use
whichOp = c = a + b || c = a - b;
whichOp = require(c >= a, "SafeMath: addition overflow") || require(b <= a, "SafeMath: subtraction overflow");
return c;
}
I expected the new merged function to work just fine.
But I am getting the error message telling me that there is an overflow.
I'm looking for a concise one line method to get a single value from a DataTable using lambda using VB.Net
This code works
OPT_UDLY = (From X In DATA.OPTIONs
Where X.CONTRACT = CTC
Select X.UDLY).Single()
but I'd like to get the value in one line like this (which doesn't work)
OPT_UDLY = DATA.Where(function(t) t.contract.Equals(CTC)).Distinct()
Any suggestions please?
Try this:
OPT_UDLY = Data.OPTIONs.Where(Function(t) t.CONTRACT = CTC).Select(Function(x) x.UDLY).Single()
Since you use Data.OPTIONs in the multiple LINQ lines, it should be consistently used for single line too.
Also, since you only need the UDLY element, use further Select LINQ expression in single line style, like what you did in your multiple lines.
And lastly, use Single to return the matching value if there is only one match, like what you already did.
Just remove the line feeds:
OPT_UDLY = (From X In DATA.OPTIONs Where X.CONTRACT = CTC Select X.UDLY).Single()
It's shorter and more readable than the lambda equivalent:
OPT_UDLY = Data.OPTIONs.Where(Function(t) t.CONTRACT = CTC).Select(Function(x) x.UDLY).Single()
I am getting an error indicating the wrong number of arguments when I run the following query:
SELECT
population_postcodes.*,
target_postcodes.*,
SQR( EXP(population_postcodes.longitude- target_postcodes.longitude, 2) + EXP(population_postcodes.latitude-target_postcodes.latitude, 2) ) as distance
FROM population_postcodes INNER JOIN target_postcodes on Population_postcodes.Population_postcode = Target_postcodes.Target_postcode;
Could anyone please suggest how I can fix this?
I have also tried the following code:
SELECT Population_postcodes.*, Target_postcodes.*
FROM population_postcodes
INNER JOIN target_postcodes
ON Population_postcodes.Population_postcode = Target_postcodes.Target_postcode
SQR( (population_postcodes.longitude- target_postcodes.longitude)^2 + (population_postcodes.latitude-target_postcodes.latitude)^2 ) as distance;
And this code:
SELECT Population_postcodes.*, Target_postcodes.*, SQR( (population_postcodes.longitude- target_postcodes.longitude)^2 + (population_postcodes.latitude-target_postcodes.latitude)^2 ) as distance
FROM population_postcodes
INNER JOIN target_postcodes
ON Population_postcodes.Population_postcode = Target_postcodes.Target_postcode;
Exp needs one parameter, you give two.
Old: EXP(population_postcodes.longitude- target_postcodes.longitude, 2)
New: (population_postcodes.longitude- target_postcodes.longitude)*(population_postcodes.longitude- target_postcodes.longitude)
Try replacing...
EXP(<expression>, 2)
...to...
<expression>^2
In Access, the EXP function returns e (the base of natural logarithms) raised to a power. To raise an expression to a power, use the ^ operator.
In your case, be careful to put brackets around the expression, for example...
(population_postcodes.longitude- target_postcodes.longitude)^2
...to force the power to be applied last. By default, the ^ operator is evaluated before the - operator.
I am trying the following code but nhibernate is throwing the following exception:
Expression type 'NhSumExpression' is not supported by this SelectClauseVisitor.
var data =
(
from a in session.Query<Activity>()
where a.Date.Date >= dateFrom.Date && a.Date.Date <= dateTo.Date
group a by new { Date = a.Date.Date, UserId = a.RegisteredUser.ExternalId } into grp
select new ActivityData()
{
UserID = grp.Key.UserId,
Date = grp.Key.Date,
Bet = grp.Sum(a => a.Amount < 0 ? (a.Amount * -1) : 0),
Won = grp.Sum(a => a.Amount > 0 ? (a.Amount) : 0)
}
).ToArray();
I've been looking around and found this answer
But I am not sure what I should use in place of the Projections.Constant being used in that example, and how I should create a group by clause consisting of multiple fields.
It looks like your grouping over multiple columns is correct.
This issue reported in the NHibernate bug tracker is similar: NH-2865 - "Expression type 'NhSumExpression' is not supported by this SelectClauseVisitor."
Problem is that apart from the less-than-helpful error message, it's not really a bug as such. What happens in NH-2865 is that the Sum expression contains something which NHibernate doesn't know how to convert into SQL, which result in this exception being thrown by a later part of the query processing.
So the question is, what does you sum expression contains that NHibernate cannot convert? The thing that jumps to mind is the use of the ternary operator. I believe the NHibernate LINQ provider has support for the ternary operator, but maybe there is something in this particular combination that is problematic.
However, I think your expressions can be written like this instead:
Bet = grp.Sum(a => Math.Min(a.Amount, 0) * -1), // Or Math.Abs() instead of multiplication.
Won = grp.Sum(a => Math.Max(a.Amount, 0))
If that doesn't work, try to use a real simple expression instead, like the following. If that works, we at least know the grouping itself work as expected.
Won = grp.Sum(a => a.Amount)