substitution

SymPy - substitute sybolic entries in a matrix

一个人想着一个人 提交于 2019-12-02 04:14:10
I have a python function which generates a sympy.Matrix with symbolic entries. It works effectively like: import sympy as sp M = sp.Matrix([[1,0,2],[0,1,2],[1,2,0]]) def make_symbolic_matrix(M): M_sym = sp.zeros(3) syms = ['a0:3'] for i in xrange(3): for j in xrange(3): if M[i,j] == 1: M_sym = syms[i] elif M[i,j] == 2: M_sym = 1 - syms[i] return M_sym This works just fine. I get a matrix out, which I can use for all the symbolical calculations I need. My issue is that now I want to evaluate my matrix at specified parameter-value. Usually I would just use the .subs attribute. However, since the

Prolog substitution

守給你的承諾、 提交于 2019-12-02 03:48:56
How can I replace a list with another list that contain the variable to be replaced. for example rep([x, d, e, z, x, z, p], [x=z, z=x, d=c], R). R = [z, c, e, x, z, x, p] the x to z and z doesn't change after it has been replaced. so far I did only the one without the list rep([], _, []). rep(L1, H1=H2, L2) :- rep(L1, H1, H2, L2). rep([],_,_,[]). rep([H|T], X1, X2, [X2|L]) :- H=X1, rep(T,X1,X2,L), !. rep([H|T],X1,X2,[H|L]) :- rep(T,X1,X2,L). I find your code rather confused. For one thing, you have rep/3 and rep/4 , but none of them have a list in the second position where you're passing the

Why is $1 empty in my substitution?

£可爱£侵袭症+ 提交于 2019-12-01 23:43:24
问题 I am trying to put the stuff within parentheses into the value of a src attribute in an img tag: while(<TOCFILE>) { $toc_line = $_; $toc_line =~ s/<inlineFig.*?(\.\.\/pics\/ch09_inline99_*?\.jpg)*?<\/inlineFig>/<img src="${1}" alt="" \/\>/g; $new_toc_file .= $toc_line; } So I expected to see tags like this in the output: <img src="../pics/ch09_inline99_00" alt="" /> But instead I'm getting: <img src="" alt="" /> 回答1: There's an error in your regex so that phrase will never match anything:

Whats the difference between {$var} and $var?

限于喜欢 提交于 2019-12-01 20:42:45
I would like to know when and why should I use {$var} echo "This is a test using {$var}"; and when (and why) should I use the simple form $var echo "This is a test using $var"; You would use the latter when a) not accessing an object or array for the value, and b) no characters follow the variable name that could possibly be interpreted as part of it. http://php.net/manual/en/language.variables.variable.php In order to use variable variables with arrays, you have to resolve an ambiguity problem. That is, if you write $$a[1] then the parser needs to know if you meant to use $a[1] as a variable,

How many substitutions took place in a Perl s///g?

落爺英雄遲暮 提交于 2019-12-01 15:24:49
Small example: perl -e '$s="aaabbcc";$c=()=$s=~/a/g;print"$c\n$s\n"' (m//g) outputs 3 aaabbcc whereas perl -e '$s="aaabbcc";$c=()=$s=~s/a/x/g;print"$c\n$s\n"' (s///g) outputs 1 xxxbbcc I'd like to do both things at once without having to match first: substitute and know the number of substitutions. Obviously a s///g does not return the number of substitutions in scalar context--unlike m//g does with matches. Is this possible? If yes, how? perlre, perlvar and perlop provided no help (or I just couldn't find it). s/// does return the number of substitutions made in scalar context. From perlop

How can I combine multiple nested Substitute functions in Excel?

梦想的初衷 提交于 2019-12-01 15:19:36
I am trying to set up a function to reformat a string that will later be concatenated. An example string would look like this: Standard_H2_W1_Launch_123x456_S_40K_AB Though sometimes the " S " doesn't exist, and sometimes the "40K" is "60K" or not there, and the "_AB" can also be "_CD" or _"EF". Finally, all underscores need to be changed to hyphens. The final product should look like this: Standard-H2-W1-Launch-123x456- I have four functions that if ran one after the other will take care of all of this: =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"_AB","_"),"_CD","_"),"_EF","_") =SUBSTITUTE

multiple regex substitution in multiple files using python [closed]

独自空忆成欢 提交于 2019-12-01 14:46:07
I have one project where I need to apply a dozen or so regex to about 100 files using python. 4+ hours of searching the web for various combinations including "(merge|concatenate|stack|join|compile) multiple regex in python" and I haven't found any posts regarding my need. This is a mid-sized project for me. There are several smaller regex projects that I need which take only 5-6 regex patterns applied over only a dozen or so files. While these will be a great aid in my work, the grand-daddy project is a applying a file of 100+ search, replace strings to any new file I get. (Spelling

Replacement by dictionary possible with AWK or Sed? [closed]

橙三吉。 提交于 2019-12-01 13:39:18
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . You have a dictionary, Dictionary.txt, and an input file, inFile.txt. The dictionary tells you about possible translations. The solution to a similar problem in unix shell: replace by dictionary seems to hardcode things here that I cannot fully understand. You can come up with better replacement

A better way to rewrite multiple appended replace methods using an input array of strings in python?

寵の児 提交于 2019-12-01 10:39:17
问题 I have a really ugly command where I use many appended "replace()" methods to replace/substitute/scrub many different strings from an original string. For example: newString = originalString.replace(' ', '').replace("\n", '').replace('()', '').replace('(Deployed)', '').replace('(BeingAssembled)', '').replace('ilo_', '').replace('ip_', '').replace('_ilop', '').replace('_ip', '').replace('backupnetwork', '').replace('_ilo', '').replace('prod-', '').replace('ilo-','').replace('(EndofLife)', '')

Removing consecutive duplicates words out of text using Regex and displaying the new text

*爱你&永不变心* 提交于 2019-11-30 22:22:52
Hy, I have the following code: import java.io.*; import java.util.ArrayList; import java.util.Scanner; import java.util.regex.*; / public class RegexSimple4 { public static void main(String[] args) { try { Scanner myfis = new Scanner(new File("D:\\myfis32.txt")); ArrayList <String> foundaz = new ArrayList<String>(); ArrayList <String> noduplicates = new ArrayList<String>(); while(myfis.hasNext()) { String line = myfis.nextLine(); String delim = " "; String [] words = line.split(delim); for (String s : words) { if (!s.isEmpty() && s != null) { Pattern pi = Pattern.compile("[aA-zZ]*"); Matcher