我需要在Julia中将“非”运算符应用于零和一的矩阵。在Matlab中,我会这样做:
A=not(B);
Run Code Online (Sandbox Code Playgroud)
在Julia中,我尝试这样做:
A = .~ B;
Run Code Online (Sandbox Code Playgroud)
和
A = .! B;
Run Code Online (Sandbox Code Playgroud)
它应该将0变成1,将1变成0,但是结果是我出错了,或者所有矩阵元素都是一些我没有输入的负数。提前致谢!
boost::filesystem::recursive_directory_iterator end, begin(directory);
auto num_of_files=std::count_if(begin, end,
std::not1(boost::filesystem::is_directory)));
Run Code Online (Sandbox Code Playgroud)
我试图在上面的目录迭代器上否定函数is_directory但是我遇到了一堵砖墙.我已经尝试为not1as 指定模板bool(*)(const boost::filesystem::path&)并尝试静态转换函数,但都没有成功.
我知道我可以诉诸lamdba但是如果它有效的话它会更干净.
谢谢
要求
假设现有类ICalculator的可用性,它模拟整数算术计算器并包含:
一个实例变量currentValue,它存储计算器的当前int值,并且可以被任何子类访问和修改.
方法add,sub,mul和div
ICalculator中的每个方法都接收一个int参数,并将其操作应用于currentValue并返回currentValue的新值.因此,如果currentValue的值为8且调用了sub(6),则currentValue以值2结束,并返回2.
因此,您要编写基于ICalculator的子类ICalculator2的定义.ICalculator2类有一个额外的方法,否定,不接受任何参数.否定的效果是反转currentValue的符号.例如,如果currentValue为零,则没有变化,如果是-22则变为22,如果为100,则变为-100.此外,negate返回currentValue的新值.
源代码
public class ICalculator2 extends ICalculator {
public int negate() {
int val = add(0);
if (val == -22) return val * -1;
else if (val == 100) return val * -1;
else return 0;}}
Run Code Online (Sandbox Code Playgroud)
备注:
更多提示:
您可能想要使用100以外的数字
您可能想要使用22以外的数字
你确定要使用:val
提示:
my ($INV_NB, $USAGE)=split /\|/,"9998|999999999999999";
if ($USAGE=~/^\d{15}\b/)
{
print "\nUSAGE is Valid\n";
print "length of $USAGE is ",length($USAGE);
}
Run Code Online (Sandbox Code Playgroud)
这按预期工作,但我怎么能否定这个正则表达式呢?说如果用法不是/^\d{15}\b/
if ($USAGE!=~/^\d{15}\b/)
{
print "\nUSAGE is Invalid\n";
print "length of $USAGE is ",length($USAGE);
}
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它不起作用..
这是一个家庭作业问题,我完全没有想法(C编程).
说明:
/*
* float_neg - Return bit-level equivalent of expression -f for
* floating point argument f.
* Both the argument and result are passed as unsigned int's, but
* they are to be interpreted as the bit-level representations of
* single-precision floating point values.
* When argument is NaN, return argument.
* Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while
* Max ops: 10
* Rating: 2
*/
unsigned float_neg(unsigned uf) {
return 2;
Run Code Online (Sandbox Code Playgroud)
我试过简单地返回-uf; …
可能重复:
感叹号在功能之前做了什么?
我正在查看Twitter Bootstrap JavaScript代码,我注意到他们所有的插件都包含在否定自我调用函数中.
我知道function ($) { ... }(window.jQuery);立即调用该函数.
但是!为了什么?
javascript jquery negate twitter-bootstrap self-invoking-function
我找到了一些带有 find ansible 模块的文件
- find:
paths: "/"
patterns: ["*.service"]
file_type: file
hidden: True
recurse: yes
register: find_results
when: ansible_service_mgr == "systemd"
Run Code Online (Sandbox Code Playgroud)
现在我想检查修改某些文件的权限:
- file:
path: "{{ item.path }}"
owner: root
group: root
mode: 0644
with_items:
- "{{ find_results.files }}"
when:
- item.path | match("/sys/devices/power/events/*")
- ansible_service_mgr == "systemd"
Run Code Online (Sandbox Code Playgroud)
问题是我不想匹配。我想要所有与该路径不匹配的东西?
如何否定匹配过滤器?(!,不是等)?
unsigned char a = 10,b;
b = ~a;
printf(" %d \n ",b);
Run Code Online (Sandbox Code Playgroud)
输出:
245
如果我使用相同的程序int而不是unsigned charo/p更改
-11
我想将正值转换为负值,例如:
let a: Int = 10
Run Code Online (Sandbox Code Playgroud)
转到它-10,我当前的想法是将其用于多个-1
a * -1
Run Code Online (Sandbox Code Playgroud)
我不确定这是否正确,知道吗?
我正在编写一个简单的文件夹观察程序,我想忽略一个temp.temp文件,该文件在扫描时被复制到文件夹中,因此程序将检测放在文件夹中的任何内容并忽略temp.temp文件.目前我已经有程序检测IMG文件来解决问题.
if(e.FullPath.Contains("IMG"))
{
MessageBox.Show("You have a Collection Form: " + e.Name);
Process.Start("explorer.exe", e.FullPath);
}
Run Code Online (Sandbox Code Playgroud)