Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Pointwise operations between scalar and vector #707
Is there a smart way to do this? Because I can't find any in the documentation.
Let's say I have something like
but with divison and power I have some issues, what is in my mind is something like
is there a smarter way to do this than replacing every number in the string with number*ones(..)?
I tried the element-wise scalar vector divide
a = 1:10 b = 4 b./a // = [4, 2, 1.333, 1, 0.8, 0.667, 0.571, 0.5, 0.444, 0.4] (b*ones(size(a)))./a // = [4, 2, 1.333, 1, 0.8, 0.667, 0.571, 0.5, 0.444, 0.4]
I'm not sure why
... I wonder if this is the same code that deals with string coercion because that was identified as being a little bit inconsistent recently.
I've found the issue I was facing. With variables it works fine
But when i try to do something like
I've found a solution doing
but i would like to know if there is a better way. Since my work has to operate with arrays I currently parse the equation string to change every operation to pointwise, I could change every number to (number) too,but is there a smarter way to deal with this issue?
Ah, I get it. The parser parses
I will fix this by making the parser more strict such that it doesn't consider
nya! when operands become operators
Are there any operators ending in
Well, if there are no operands ending with . (and i hope there are not) this is handling it well for me
so it's working fine for now
Be aware that your expression manipulation would also change some valid vector-vector operations into alternatives vector-vector operations e.g dot product
I think your dot might need escaping if I understand correctly?
Alternatively if you want a more thorough number regex:
Handles signs, decimals and exponents, excludes trailing but not leading decimal.