Is it possible to apply colon operator on an expression in MATLAB?

▼魔方 西西 提交于 2019-12-24 04:54:06
问题 It's very convenient if it was possible to use colon operator on a expression. Well to my knowledge, it's not possible. For example when I want to calculate the differences between two matrices, I have to do it in two lines. diff = (a - b); err = sum(abs(diff(:))); instead of diff = sum(abs((a-b)(:))); Is there anyway around it? 回答1: You can get around syntax limitations with anonymous helper functions. EG oneD = @(x)x(:); diff = sum(abs(oneD(a-b)))); Still takes two lines though. 回答2: Two

Unable to map docker volume with colon

风格不统一 提交于 2019-12-23 22:01:18
问题 Is there a way to mount a host directory as a data volume while the host directory path contains a colon? Example -v /colon:path/test:data In that case it's treating data as additional option. The /colon:path/test is a correct Unix path. 回答1: Yes. With the --mount option you can specify the source and destination. This option was added to Docker 17.05.0. --mount type=bind,source=/colon:path/test,destination=/data Note: You must use absolute pathnames. I'm assuming the destination is /data.

Combination of colon-operations in MATLAB

六月ゝ 毕业季﹏ 提交于 2019-12-23 19:25:55
问题 I have a question concerning the colon operator and expansion of vectors in MATLAB. My problem is to understand how the following line of code expands, to be able to use it for other sequences. The line of MATLAB code is: a(1:2:5) = 1:-4:-7 Note that a is not defined before the expansion. This returns the vector a = 1 0 3 0 -7 I know how the colon operator works with {start}:{step}:{stop} , my problem is to understand how and why the combination of a(1:2:5) and 1:-4:-7 returns a vector of

What does the colon (:) exactly stand for in Swi-Prolog?

房东的猫 提交于 2019-12-23 09:32:31
问题 I could not find explicitly what (:) stands for in prolog. In interactive mode you can see the following evidence: ?- display(a:b). :(a,b) true. ?- display([a,b,c]). .(a,.(b,.(c,[]))) true. ?- display(a:b:c:[]). :(a,:(b,:(c,[]))) true. ?- a:b:REST = a:TAIL. TAIL = b:REST. For what purpose (:) is introduced? I could not find any details for it in www. Seems that it gives another syntactic way of talking about recursive structures as Lists. We can say that it is Right-associative, what is its

Lua: colon notation, 'self' and function definition vs. call

限于喜欢 提交于 2019-12-22 05:52:49
问题 I'm getting terribly confused by the colon notation used when defining/calling Lua functions. I thought I'd got my head round it until I saw this piece of code: function string.PatternSafe( str ) return ( str:gsub( ".", pattern_escape_replacements ) ); end function string.Trim( s, char ) if char then char = char:PatternSafe() else char = "%s" end return string.match( s, "^" .. char .. "*(.-)" .. char .. "*$" ) or s end What's confusing me here is that string.PatternSafe() doesn't reference

Python: single colon vs double colon

倾然丶 夕夏残阳落幕 提交于 2019-12-18 16:07:11
问题 What is the difference between single and double colon in this situation? data[0:,4] vs data[0::,4] women_only_stats = data[0::,4] == "female" men_only_stats = data[0::,4] != "female" I tried to replace data[0::,4] with data[0:,4] and I see no difference. Is there any difference in this or another case? data is 2-dimensional array with rows like ['1' '0' '3' 'Braund, Mr. Owen Harris' 'male' '22' '1' '0' 'A/5 21171' '7.25' '' 'S'] 回答1: No , there is no difference. See the Python documentation

Are colons allowed in URLs?

萝らか妹 提交于 2019-12-18 02:09:09
问题 I thought using colons in URIs was "illegal". Then I saw that is using URIs like What do you feel about the usage of colons in URIs? How do I make my Apache server work with the "colon" syntax because now it's throwing the "Access forbidden!" error when there is a colon in the first segment of the URI? 回答1: Colons are allowed in the URI path. But you need to be careful when writing relative URI paths with a colon since it is not allowed when used

Selecting an ID with a colon in it with jQuery

◇◆丶佛笑我妖孽 提交于 2019-12-17 06:49:19
问题 I'm working on a pre-written module for a site, and I need to target an element with the id test:two . Now, this element has a colon in it, so jQuery is presumably and understandably seeing the 'two' as a pseudo class. Is there any way of targeting this element with jQuery? Also, changing the ID is not possible. Believe me, if I could I would. I've put together an example: $('#test').css('background','red'); $(document.getElementById('test:two')).css('background','blue'); $('#test:two').css(

What would 'std:;' do in c++?

断了今生、忘了曾经 提交于 2019-12-13 11:33:38
问题 I was recently modifying some code, and found a pre-existing bug on one line within a function: std:;string x = y; This code still compiles and has been working as expected. The string definition works because this file is using namespace std; , so the std:: was unnecessary in the first place. The question is, why is std:; compiling and what, if anything, is it doing? 回答1: std: its a label, usable as a target for goto . As pointed by @Adam Rosenfield in a comment, it is a legal label name. C+

Using a colon (:) in a url with ASP.NET/IIS

青春壹個敷衍的年華 提交于 2019-12-13 05:44:25
问题 I'm implementing a custom controller in ASP.NET MVC and really want to be able to use a colon in the urls, so that I can identify class/column names and their values, like so: ...but apparently ASP.NET or IIS doesn't allow colons in urls. I did some digging and apparently it's considered a security issue, but , I'm using MVC and am handling all url paths manually (just treating them as strings), and not relating them to the file system, so I'm pretty sure this