Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary

2018-09-23 Thread Shall, Sydney via Tutor

On 23/09/2018 13:04, Peter Otten wrote:

Peter Otten wrote:


Maybe you could sort the already-sorted property_b again, with some random
offset:


import itertools
def wiggled(items, sigma):

... counter = itertools.count()
... def key(item): return random.gauss(next(counter), sigma)
... return sorted(items, key=key)
...


One more example:


s = """\

... But my actual scientific problem requires that the correlation should be
... only approximate and I do not know how close to to a perfect correlation
... it should be. So, I need to introduce some lack of good correlation when
... I set up the correlation. How to do that is my problem.
... """

print(textwrap.fill(" ".join(wiggled(s.split(), 2

But actual my scientific the requires that problem should only
correlation approximate be and not do I know how close to a perfect to
correlation should it So, be. I to lack need some introduce
correlation I of good when set correlation. up How to the that do
problem. is my

:)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutordata=01%7C01%7Csydney.shall%40kcl.ac.uk%7C185332cee28f49ed465108d6214ce8ab%7C8370cf1416f34c16b83c724071654356%7C0sdata=GBAb%2FdY2zrBqSwOl33ejT%2BzzknQx5RYNXsNEqZQXCX4%3Dreserved=0


Thanks. Most useful.

Sydney

--

_

Professor Sydney Shall
Department of Haematology/Oncology
Phone: +(0)2078489200
E-Mail: sydney.shall
[Correspondents outside the College should add @kcl.ac.uk]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary

2018-09-23 Thread Shall, Sydney via Tutor

On 23/09/2018 10:42, Peter Otten wrote:

Shall, Sydney via Tutor wrote:


What I want is the following.

I have:

property_a = [1, 6, 2, 4]
property_b = [62, 73, 31 102]


Result should approximately be:

property_b = [31, 102, 62, 73]


That is both lists change in value in exactly the same order.

Now, this is easy to achieve. I could simply sort both lists is
ascending order and I would then have an exact alignment of values is
ascending order. The correlation would be a perfect linear relationship,
I suppose.

But my actual scientific problem requires that the correlation should be
only approximate and I do not know how close to to a perfect correlation
it should be. So, I need to introduce some lack of good correlation when
I set up the correlation. How to do that is my problem.

I hope this helps to clarify what my problem is.


Maybe you could sort the already-sorted property_b again, with some random
offset:


import itertools
def wiggled(items, sigma):

... counter = itertools.count()
... def key(item): return random.gauss(next(counter), sigma)
... return sorted(items, key=key)
...

wiggled(range(20), 3)

[0, 5, 2, 4, 1, 6, 7, 8, 3, 9, 11, 10, 13, 14, 16, 12, 18, 17, 19, 15]

wiggled([31, 102, 62, 73], .8)

[102, 31, 62, 73]

wiggled([31, 102, 62, 73], .8)

[31, 102, 62, 73]

wiggled([31, 102, 62, 73], .8)

[31, 102, 62, 73]

wiggled([31, 102, 62, 73], .8)

[31, 62, 102, 73]


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutordata=01%7C01%7Csydney.shall%40kcl.ac.uk%7Cb9cbdce8c20e45dd3ff508d621390143%7C8370cf1416f34c16b83c724071654356%7C0sdata=yNo7hMVl7dYmH6d74MBaab5e5g6bPoWoqkza5TS1bXY%3Dreserved=0




Thanks to Oscar and to Pater for their help. They have set me on the 
correct path.
The crucial advice to was to look at the randomisation procedures. I 
have used a procedure similar to that suggested by Peter and it works well.


Cheers,

Sydney

_

Professor Sydney Shall
Department of Haematology/Oncology
Phone: +(0)2078489200
E-Mail: sydney.shall
[Correspondents outside the College should add @kcl.ac.uk]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary

2018-09-23 Thread Peter Otten
Peter Otten wrote:

> Maybe you could sort the already-sorted property_b again, with some random
> offset:
> 
 import itertools
 def wiggled(items, sigma):
> ... counter = itertools.count()
> ... def key(item): return random.gauss(next(counter), sigma)
> ... return sorted(items, key=key)
> ...

One more example:

>>> s = """\
... But my actual scientific problem requires that the correlation should be 
... only approximate and I do not know how close to to a perfect correlation 
... it should be. So, I need to introduce some lack of good correlation when 
... I set up the correlation. How to do that is my problem.
... """
>>> print(textwrap.fill(" ".join(wiggled(s.split(), 2
But actual my scientific the requires that problem should only
correlation approximate be and not do I know how close to a perfect to
correlation should it So, be. I to lack need some introduce
correlation I of good when set correlation. up How to the that do
problem. is my

:)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary

2018-09-23 Thread Peter Otten
Shall, Sydney via Tutor wrote:

> What I want is the following.
> 
> I have:
> > property_a = [1, 6, 2, 4]
> > property_b = [62, 73, 31 102]
> 
> Result should approximately be:
> > property_b = [31, 102, 62, 73]
> 
> That is both lists change in value in exactly the same order.
> 
> Now, this is easy to achieve. I could simply sort both lists is
> ascending order and I would then have an exact alignment of values is
> ascending order. The correlation would be a perfect linear relationship,
> I suppose.
> 
> But my actual scientific problem requires that the correlation should be
> only approximate and I do not know how close to to a perfect correlation
> it should be. So, I need to introduce some lack of good correlation when
> I set up the correlation. How to do that is my problem.
> 
> I hope this helps to clarify what my problem is.

Maybe you could sort the already-sorted property_b again, with some random 
offset:

>>> import itertools
>>> def wiggled(items, sigma):
... counter = itertools.count()
... def key(item): return random.gauss(next(counter), sigma)
... return sorted(items, key=key)
... 
>>> wiggled(range(20), 3)
[0, 5, 2, 4, 1, 6, 7, 8, 3, 9, 11, 10, 13, 14, 16, 12, 18, 17, 19, 15]
>>> wiggled([31, 102, 62, 73], .8)
[102, 31, 62, 73]
>>> wiggled([31, 102, 62, 73], .8)
[31, 102, 62, 73]
>>> wiggled([31, 102, 62, 73], .8)
[31, 102, 62, 73]
>>> wiggled([31, 102, 62, 73], .8)
[31, 62, 102, 73]


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary

2018-09-23 Thread Shall, Sydney via Tutor

On 21/09/2018 00:01, Oscar Benjamin wrote:

Sydney wrote and Alan forwarded:



I have, I suspect, an elementary problem that I am too inexperienced to
resolve.

I have two numpy arrays, each representing the values of a specific
property of a set of cells.

Now, I want to associate the two values for each cell, that is for each
index of the numpy array. But I want to associate them ROUGHLY, that
means, APPROXIMATELY, so that there is a weak, linear correlation
between the values representing one property and the values representing
the second property of each individual cell.

Up to now I have used the following procedure.
I have divided each population of values into four segments based on the
value of the standard deviation thus.

1. values > mean + 1 std (sigma)
2. values > mean but < mean + 1 std (sigma)
3. values < mean but > mean + 1 std (sigma)
4. values < mean + 1 std (sigma).

Then I randomly select a value from group 1 for the first property and I
associate it with a randomly selected sample of the second property from
its group 1. And so on through the total population. This gave me a very
rough linear association between the two properties, but I am wondering
whether I can do it in a simpler and better way.



Hi Sydney,

I feel like I would definitely be able to solve your problem if I
understood what you're talking about (I'm sure others here could as well).
Please don't be put off by this but I don't think you've explained it very
well.

Perhaps if you give an example of what the input and output of this
operation is supposed to look like then you would get a response. The
example might look like:

I have these arrays as input:


property_a = [1, 6, 2, 4]
property_b = [6, 3, 4, 6]


Then I want a function that gives me this output


associated_values = myfunction(a, b)
associated_values

[1, 3, 5, 2]

Some explanation why you want this, how you know that's the output you
want, and what any of it means would likely help...

If you already have something that does what you want then it would make
sense to show it but if your code is complicated then please try to
simplify it and use only a small amount of data when showing it here. There
is some advice for posting this kind of thing to a mailing list here:
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fsscce.org%2Fdata=01%7C01%7Csydney.shall%40kcl.ac.uk%7C77fe09364c79190308d61f4d4112%7C8370cf1416f34c16b83c724071654356%7C0sdata=DAhLxDli1vM%2BBcRXKemRo0sa%2BVJErJPZ%2Bwy5UHvUR4s%3Dreserved=0

--
Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutordata=01%7C01%7Csydney.shall%40kcl.ac.uk%7C77fe09364c79190308d61f4d4112%7C8370cf1416f34c16b83c724071654356%7C0sdata=Benb%2BsxqZr1Rhdj8jG81KRurndfNVnBGx0%2B3z9VXd54%3Dreserved=0


Thank you Oscar. Fair comment.

What I want is the following.

I have:
> property_a = [1, 6, 2, 4]
> property_b = [62, 73, 31 102]

Result should approximately be:
> property_b = [31, 102, 62, 73]

That is both lists change in value in exactly the same order.

Now, this is easy to achieve. I could simply sort both lists is 
ascending order and I would then have an exact alignment of values is 
ascending order. The correlation would be a perfect linear relationship, 
I suppose.


But my actual scientific problem requires that the correlation should be 
only approximate and I do not know how close to to a perfect correlation 
it should be. So, I need to introduce some lack of good correlation when 
I set up the correlation. How to do that is my problem.


I hope this helps to clarify what my problem is.

Sydney

--

_

Professor Sydney Shall
Department of Haematology/Oncology
Phone: +(0)2078489200
E-Mail: sydney.shall
[Correspondents outside the College should add @kcl.ac.uk]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary

2018-09-20 Thread Oscar Benjamin
Sydney wrote and Alan forwarded:

>
> I have, I suspect, an elementary problem that I am too inexperienced to
> resolve.
>
> I have two numpy arrays, each representing the values of a specific
> property of a set of cells.
>
> Now, I want to associate the two values for each cell, that is for each
> index of the numpy array. But I want to associate them ROUGHLY, that
> means, APPROXIMATELY, so that there is a weak, linear correlation
> between the values representing one property and the values representing
> the second property of each individual cell.
>
> Up to now I have used the following procedure.
> I have divided each population of values into four segments based on the
> value of the standard deviation thus.
>
> 1. values > mean + 1 std (sigma)
> 2. values > mean but < mean + 1 std (sigma)
> 3. values < mean but > mean + 1 std (sigma)
> 4. values < mean + 1 std (sigma).
>
> Then I randomly select a value from group 1 for the first property and I
> associate it with a randomly selected sample of the second property from
> its group 1. And so on through the total population. This gave me a very
> rough linear association between the two properties, but I am wondering
> whether I can do it in a simpler and better way.
>

Hi Sydney,

I feel like I would definitely be able to solve your problem if I
understood what you're talking about (I'm sure others here could as well).
Please don't be put off by this but I don't think you've explained it very
well.

Perhaps if you give an example of what the input and output of this
operation is supposed to look like then you would get a response. The
example might look like:

I have these arrays as input:

>>> property_a = [1, 6, 2, 4]
>>> property_b = [6, 3, 4, 6]

Then I want a function that gives me this output

>>> associated_values = myfunction(a, b)
>>> associated_values
[1, 3, 5, 2]

Some explanation why you want this, how you know that's the output you
want, and what any of it means would likely help...

If you already have something that does what you want then it would make
sense to show it but if your code is complicated then please try to
simplify it and use only a small amount of data when showing it here. There
is some advice for posting this kind of thing to a mailing list here:
http://sscce.org/

--
Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor