« first day (948 days earlier)      last day (3545 days later) » 

4:39 AM
any one here to check some basic command for me?
 
5:19 AM
never mind, figured it out !
 
 
4 hours later…
9:09 AM
Any one can tell me what are the aplications of finding local maxima in images? Or where can I find any?
 
9:55 AM
@Trollkemada One example.
 
@Pickett Thanks, I was looking for more general aplications, but I guess that is something =)
 
@Trollkemada Whenever ImageCorrelate is used there is a high probability that you will want to find the local maximum after that because that would signify where the correlation of the kernel and the image is the largest, such as in this Q&A.
Unfortunately I don't know any really general applications but I wish you the best of luck.
 
10:11 AM
Thanks
 
 
1 hour later…
11:27 AM
@Trollkemada peak-finding, perhaps for identifying stars/features in astronomy images?
 
 
6 hours later…
5:31 PM
How to export .mtl files for 3D textured objects didn't receive any attention (just 26 views), which is a pity. So take a look at it if you haven't.
 
6:01 PM
I was going to ask this, but thought might be asked before. Is there an easy way to add a condition when using Cases to tell it what to generate for each pattern matched? For example, given

lis = {x, x + y, z + n};
Cases[lis, Alternatives[Plus[x_, y_], x_] :> {x, y}]
the result is {{x}, {x, y}, {n, z}}  but I like the result to be {{x,0}, {x, y}, {n, z}}
i.e. when the x_ only is matched, I want to tell it to generate {x,0} and not {x}. But not able to find the right way to do it.
 
@Nasser Perhaps you could use default values as in Cases[lis, Plus[x_, y_: 0] :> {x, y}]
 
@Pickett thanks. This works on this example, let me try it on other example. I do not understand how it works. Is x_ matched to Plus[x] then in this case? will let you know..
 
@Nasser TBH it felt like magic that it worked... Plus isn't even present i "x" but somehow the pattern matching engine recognizes it anyway. So do try it on some other things, I'm not so sure it can be relied upon.
Anyway I guess the idea is that the pattern matcher tries two cases: one where y exists and one where it doesn't. When it doesn't exist it rewrites the expression from Plus[x_]->x_ and substitutes in 0 for y.
 
6:16 PM
@Pickett my main example is a bit more complicated, so I made this simple one. I am trying it on the other complicated one. But there I do not have Plus, I have Times actually. But I am trying to see if I incorporate this in there.
 
ok
 
@Pickett I can't figure how to make it work with my other example. May be I'll make another MWE that has the other example then....
 
@Nasser @Pickett Extra care has been taken to make functions like Plus and Times work with pattern matching. Some of this happens at the box level. Try, e.g., MakeExpression[Plus[x],StandardForm]
It is resolved to just x before evaluated in the kernel
 
@mfvonh Yes, I have observed this behavior before.
 
Here is my actual example
lis = 6 + 1/z^4 + 4/z^2 + 4 z^2 + z^4;
Cases[lis, Alternatives[x_. Power[z, e_.], Times[x_, Power[z, e_.]], x_.] :> {x, e}]
which gives
{{6}, {1, -4}, {4, -2}, {4, 2}, {1, 4}}
I want it to show {6,0} there.
So when it matches just the x_. (the last guy) then it should make "e=0" in there.
I think there should be a general method to this. Where is one of the alternative match, then emit specific pattern, Like this:
Cases[list, Alternatives[ pat1_ :> this, pat2 :>that ] ]
But the above does not work.
by default M assign the null sequence to "e" in there, so it ends up with {6}.
 
6:31 PM
I agree, that would be nice.
Again, we can solve this particular MWE:
Cases[r, Alternatives[
x_. Power[z, e_.],
x_ Power[z, e_.],
Dot[x_, e_: 0]
] :> {x, e}]
But who knows what other patterns we can't solve like this.
(This pattern will match Dot[x,y] which the original didn't.)
 
@Pickett You are using different example from one I posted? Here is the MWE:
lis = 6 + 1/z^4 + 4/z^2 + 4 z^2 + z^4;
Cases[lis, Alternatives[x_. Power[z, e_.], Times[x_, Power[z, e_.]], x_.] :> {x, e}]
 
@Nasser How is mine different? Also, it works for me in V10...
 
@Pickett I mean you have different code there. You wrote
Cases[r, Alternatives[x_. Power[z, e_.],x_ Power[z, e_.],Dot[x_, e_: 0]] :> {x, e}]
but mine was Cases[lis, Alternatives[x_. Power[z, e_.], Times[x_, Power[z, e_.]], x_.] :> {x, e}], what happens to the Times part?
@Pickett I tried now your on my example, I get an error:
lis = 6 + 1/z^4 + 4/z^2 + 4 z^2 + z^4;
Cases[lis, Alternatives[x_. Power[z, e_.], Times[x_, Power[z, e_.]], Dot[x_., e_: 0]] :> {x, e}]
Ami doing something wrong?
"No default setting found for Dot in position 1 when length is 2. >>"
 
x_ Power[z,e_.] == Times[x_, Power[x,e_.]]
 
@Pickett oh, I did not notice you changed it to be implicit like this. Yes ofcourse, I liked to keep it explicit so I see the Head more clearly. Ok, no problem.
 
6:42 PM
OK, found it. You wrote: Dot[x_.,e:0] which is Dot[Dot[x],e:0] but I wrote Dot[x_,e_:0]
You have a dot inside Dot.
@Nasser I usually prefer to write out the heads for clarity as well.
 
@Pickett ok, removed the dot. Now it worked ! thanks. But I still feel, even though this is a smart trick, there ought to be a more general approach.
 
@Nasser I agree, let's wait and see if someone else comes around.
 
There should be a way to do Cases[expr, {pat1 :> this, pat2 :>that}] Because in more complicated parsing, I might not be able to find a trick like your that will work.
@Pickett do you think this is worth posting on main board? if so, I can post my example there and ask for a more general Alternative with its own rule generation. I assumed first this exist but can't find the syntax for it. Like anything in Mathematica, it is sometimes just hard to figure the correct syntax to do something.
 
@Nasser I'm doubtful that such a solution exists but if you ask at least you'll know for sure.
 
@Nasser what about
Scan[# /. {
x_. Power[z, e_.] :> Sow[{x, e}],
Times[x_, Power[z, e_.]] :> Sow[{x, e}],
x_Integer :> Sow[{x, 0}]} &, lis] // Reap
Doesn't use Cases of course
the _Integer can be removed actually
I think this approach should generalize pretty well
 
6:59 PM
@mfvonh another smart solution! Yes, this is what I was looking for, a more general approach. I did not even think of using something other than cases. If it is ok, I'd like to post this as question and you can post the answer there and others also. I think this is useful solution you have there and not many would think of it. I assume it will generalize to other situations. But it works nice for me now. Thanks.
 
@Nasser By all means. I am curious to see what people come up with; it definitely would be nice if there were a way to pull it off with Cases as you described
 
rules = {Alternatives[x_. Power[z, e_.], Times[x_, Power[z, e_.]]] :> {x, e}, x_Integer :> {x, 0}};
Map[Cases[lis , #] &, rules]
Actually that doesn't work as well as @mfvonh's solution. I thought at first that it would.
But I bet if you ask this kind of question you will get very good answers on the main site...
 
I thought it might be possible to use Sow inside /; (using Cases) but I haven't found a way to make it work
 
 
1 hour later…
acl
8:10 PM
@mfvonh doesn't this work
Cases[Range[200], x_ /; (Sow[x]; x < 50)] // Reap
or did you mean something else?
 
@acl I was trying to come up with a solution to @Nasser's question at the beginning of this last clump of messages
 
acl
@mfvonh Yeah sorry, was reading this from the bottom up
 
@acl I always do that, no worries :)
 
acl
It's interesting that this is the first time this creates a problem.
(Or maybe it's worrying)
 
You mean Nasser's question?
 
acl
8:20 PM
@mfvonh No, that I read backwards
 
@acl I often find it difficult to find the beginning of threads in here. Sometimes people are @'ing each other over the course of several days and I find myself commenting without being fully aware of the discussion that has already taken place
 
@mfvonh I've posted the question. I tried to be as clear as I can, I hope it is not long winded.
0
Q: What is the correct way to use specific rule for specific pattern match when parsing an expression?

NasserThe hammer I use now for everything I see that needs parsing with patterns is Cases. So, I was trying to write a simple pattern based parser that accepts any output from Expand(f[z]) where f[z] is rational function of z only. For example, it take such input as Expand[(z + 1/z)^4] (*6 + 1/z^4 ...

 
8:36 PM
@Nasser Looks good to me; I think the question is clear. I'll post in a few minutes
 

« first day (948 days earlier)      last day (3545 days later) »