-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NDArray operation '&' #129
Comments
Can you provide the equivalent python snippet for comparison? |
import numpy as np
data = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90, 100,110,120])
conlist = [data <= 30, (data >=50) & (data < 100), data>=100]
choiselist = [66, 77, 88]
dataReClass = np.select(conlist, choiselist, default=0)
print(dataReClass) the result is below |
henon
added a commit
that referenced
this issue
Sep 1, 2024
The operators were only defined for scalars, now I added overloads for arrays and it works: [TestMethod]
public void IssueByXiaozhu1988()
{
//>>> data = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120])
//>>> (data >= 50) & (data < 100)
//array([False, False, False, False, True, True, True, True, True,
// False, False, False])
var data = np.array(new[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120 });
Console.WriteLine(((data >= 50) & (data < 100)).repr);
Assert.AreEqual("array([False, False, False, False, True, True, True, True, True,\n False, False, False])", ((data >= 50) & (data < 100)).repr);
Console.WriteLine(((data >= 50) | (data < 100)).repr);
Assert.AreEqual("array([ True, True, True, True, True, True, True, True, True,\n True, True, True])", ((data >= 50) | (data < 100)).repr);
Console.WriteLine(((data >= 50) ^ (data < 100)).repr);
Assert.AreEqual("array([ True, True, True, True, False, False, False, False, False,\n True, True, True])", ((data >= 50) ^ (data < 100)).repr);
} |
thanks for your reply
I will try it tomorrow
best wishes👌👌👌
…---Original---
From: "Meinrad ***@***.***>
Date: Sun, Sep 1, 2024 16:59 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [SciSharp/Numpy.NET] NDArray operation '&' (Issue #129)
The operators were only defined for scalars, now I added overloads for arrays and it works:
[TestMethod] public void IssueByXiaozhu1988() { //>>> data = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) //>>> (data >= 50) & (data < 100) //array([False, False, False, False, True, True, True, True, True, // False, False, False]) var data = np.array(new[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120 }); Console.WriteLine(((data >= 50) & (data < 100)).repr); Assert.AreEqual("array([False, False, False, False, True, True, True, True, True,\n False, False, False])", ((data >= 50) & (data < 100)).repr); Console.WriteLine(((data >= 50) | (data < 100)).repr); Assert.AreEqual("array([ True, True, True, True, True, True, True, True, True,\n True, True, True])", ((data >= 50) | (data < 100)).repr); Console.WriteLine(((data >= 50) ^ (data < 100)).repr); Assert.AreEqual("array([ True, True, True, True, False, False, False, False, False,\n True, True, True])", ((data >= 50) ^ (data < 100)).repr); }
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is the code i write by C#
there is an error in the following line
conditions[1] = (ndarrya > 50)&(ndarrya <= 100);
Visual studio warn that 'the operation & can not be userd between NDarray[bool]
I just want to know how to write the Multiple Conditions
wish for you reply
The text was updated successfully, but these errors were encountered: