The logic operator of the ndarray


#1

I just would like to know if the ndarray has some logic operations, such as ‘and(&)’, ‘or(|)’ etc.
I did not find any in the document.

Thanks


#2

There is no logical operator in MXNet. However typically anything you’d like to achieve with logical operators can be achieved with existing operators such as nd.where(). If you explain the problem you’re trying to solve using logical operators, I may be able to point you int he right direction.


#3

I would like to compute the true positive for a given class in a multi-class category task.
Assume that gt_label stands for the ground truth label of all examples; pred_label stands for the predicted label. Then, for class c, the TP© can be computed as:
TP© = (gt_label == c & pred_label == c).sum()
Now, I compute it like this:
TP© = ((gt_label == c) * (pred_label == c)).sum()
But, I don’t think it is elegant.


#4

I’d say your solution is pretty elegant :slight_smile: I can’t think of a better way.