Message Boards Message Boards

0
|
3746 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Can't retrieve a Key in an Association, but the key is listed in it

Posted 2 years ago

Hello,

I've encountered a strange behavior in Mathematica, and it is quickly reproducible

Table[q, {q, 0.01, 0.99, 0.01}]
Table[-Sqrt[2] InverseErfc[2 q],{q, 0.01, 0.99, 0.01}]
ndQuantile = AssociationThread[%% -> %] 

Calling ndQuantile[0.35] prints that this Key is missing, but I most definitely can see it listed in the Association dataset. Calling every other keys seem to work fine (0.4, 0.45 etc).

Using Table to make a list of every values in the Association lets me retrieve the desired value, so I'm lost.

Table[ndQuantile[x],{x,0.01,0.99,0.01}]
%[[35]]

Am I doing something wrong ?

Thank you.

POSTED BY: Clarisse Wagner
4 Replies

Frankly, it is not the second-best idea to use Reals as keys. .35 is not one of the keys,

Actually, it is 0.35000000000000003.

POSTED BY: Robert Nowak

As Henrik points out, it's a bit hard to see why you would want to do this. Would it not be simpler to write a function:

ndQuantile[q_] := -Sqrt[2] InverseErfc[2 q]

So you can just do

ndQuantile[0.35]
POSTED BY: Gareth Russell

Clarisse,

the problem becomes apparent when you look at your keys in FullForm or InputForm:

Keys[ndQuantile] // FullForm

I do not know about your needs here, but would Interpolation not be a better choice?

Regards -- Henrik

POSTED BY: Henrik Schachner

Hello Henrik,

Thank you for your input.

Inspecting what you suggested, I came up with the solution to my problem :

Table[N[q/100], {q, 1, 99, 1}]
Table[-Sqrt[2] InverseErfc[2 q], {q, 0.01, 0.99, 0.01}]
ndQuantile = AssociationThread[%% -> %]

I suppose that it's more robust to iterate inside a Table with integers.

POSTED BY: Clarisse Wagner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract