logical-operators

Loop in R: how to save the outputs?

好久不见. 提交于 2019-11-28 11:20:57
I am trying to save the data from a loop of logical tests. So I have the following data: T1 <- matrix(seq(from=100000, to=6600000,length.out=676),26,26) # a matrix of 26X26 - here with illustrive values minmax <- seq(from=1,to=49,by=1) # creates a sequence Fstep <- 6569141.82/minmax # define a vector from 0 to 6569141.82 with 49 divisions F <- rev(round(Fstep,0)) # round the vector values and re order them F I have runned the following loop for (i in 1:49) { print(T1 > F[i]) # I used print to see the results in the screen } This loop returns me 49 matrices filled in with logical values (True

Matlab index to logic indexing

折月煮酒 提交于 2019-11-28 11:12:46
I have given a list of indices, e.g. i = [3 5] and a vector v = 1:6 . I need a function f which returns the logical map for the vector v given the indices i , e.g.: f(i, length(v)) = [0 0 1 0 1 0] Since I will call this function several million times, I would like to make it as fast as possible. Is there a builtin function which performs this task? I know I'm late in the game, but I really wanted to find a faster solution which is just as elegant as ismember . And indeed there is one, that employs the undocumented ismembc function: ismembc(v, i) Benchmark N = 7; i = [3 5]; %// slayton's

Behavior of summing !is.na() results

北战南征 提交于 2019-11-28 10:54:11
Why does the first line return TRUE, and the third line returns 1? I would expect both lines to return 1. What is the exact meaning of those extra two parentheses in the third line? !is.na(5) + !is.na(NA) # TRUE (!is.na(5)) + (!is.na(NA)) # 1 edit: should check these multiple times. The original problem was with !is.na() , thought it replicated for is.na() . But it didn't :) ! has a weird, counter-intuitive precedence in R. Your first code is equivalent to !(is.na(5) + !is.na(NA)) That is, ! has lower precedence than + . 来源: https://stackoverflow.com/questions/17651687/behavior-of-summing-is

Short circuiting statement evaluation — is this guaranteed? [C#]

╄→гoц情女王★ 提交于 2019-11-28 10:50:28
Quick question here about short-circuiting statements in C#. With an if statement like this: if (MyObject.MyArray.Count == 0 || MyObject.MyArray[0].SomeValue == 0) { //.... } Is it guaranteed that evaluation will stop after the "MyArray.Count" portion, provided that portion is true? Otherwise I'll get a null exception in the second part. Yes, this is guaranteed. C# Language Specification - 7.11 Conditional logical operators : The && and || operators are called the conditional logical operators. They are also called the "short-circuiting" logical operators. Therefore they will support logical

What happens when you logical not a float?

我怕爱的太早我们不能终老 提交于 2019-11-28 10:43:11
I assume this just returns an int. Is there anything else going on I should be aware of? C/C++ differences? float a = 2.5; !a; // What does this return? Int? Float? Regarding C++, quoting C++11 §5.3.1/9: The operand of the logical negation operator ! is contextually converted to bool ; its value is true if the converted operand is false and false otherwise. The type of the result is bool . So what's really relevant here is the behavior of static_cast<bool>(some_float) – quoting §4.12/1: A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a

What is the type of the logical operators?

試著忘記壹切 提交于 2019-11-28 09:22:34
问题 I want to use them as a parameter to a method of my Region struct: private func combineWith(region: RegionProtocol, combine: (Bool, Bool) -> Bool) -> Region { return Region() {point in combine(self.contains(point), region.contains(point)) } } But apparently, (Bool, Bool) -> Bool) is not what && or || are. If you know, please let me know how you found out. 回答1: If you "cmd-click" on the word "Swift" in the statement import Swift in Xcode and search for || then you'll find that it is declared

C Preprocessor testing definedness of multiple macros

[亡魂溺海] 提交于 2019-11-28 07:58:29
I searched the site but did not find the answer I was looking for so here is a really quick question. I am trying to do something like that : #ifdef _WIN32 || _WIN64 #include <conio.h> #endif How can I do such a thing? I know that _WIN32 is defined for both 32 and 64 bit windows so I would be okay with either for windows detection. I am more interested in whether I can use logical operators like that with preprocessor directives, and if yes how, since the above does not work. Compiling with gcc I get : warning: extra tokens at end of #ifdef directive , and it basically just takes the first

Logical AND in Forth?

好久不见. 提交于 2019-11-28 02:46:51
问题 I know the AND word defines binary and ... but what defines logical and ? 回答1: The same word, AND , is also used for logical and . But the two input values to AND are recommended to be well-formed flags ; true and false are represented by two values, bits all set (-1) and bits all unset (0). Other values than these may work as true (as in C), but may lead to subtle errors. All comparison operators return well-formed flags, but for instance - does not. The following evaluates to false (0). 7 5

unusual ternary operation

ぃ、小莉子 提交于 2019-11-28 02:43:42
问题 I was asked to perform this operation of ternary operator use: $test='one'; echo $test == 'one' ? 'one' : $test == 'two' ? 'two' : 'three'; Which prints two (checked using php). I am still not sure about the logic for this. Please, can anybody tell me the logic for this. 回答1: Well, the ? and : have equal precedence, so PHP will parse left to right evaluating each bit in turn: echo ($test == 'one' ? 'one' : $test == 'two') ? 'two' : 'three'; First $test == 'one' returns true, so the first

Boolean OR in sed regex

穿精又带淫゛_ 提交于 2019-11-28 02:38:08
问题 I'm trying to replace all references of a package named boots in a configuration file. The line format is add fast (package OR pkg) boots-(any-other-text) , e.g.: add fast package boots-2.3 add fast pkg boots-4.5 I want to replace it with: add fast pkg boots-5.0 I've tried the following sed commands: sed -e 's/add fast (pkg\|package) boots-.*/add yinst pkg boots-5.0/g' sed -e 's/add fast [pkg\|package] boots-.*/add yinst pkg boots-5.0/g' What's the right regex? I think I'm missing something