[Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary
Shall, Sydney
sydney.shall at kcl.ac.uk
Fri Sep 21 07:16:37 EDT 2018
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%2F&data=01%7C01%7Csydney.shall%40kcl.ac.uk%7C77fe088889364c79190308d61f4d4112%7C8370cf1416f34c16b83c724071654356%7C0&sdata=DAhLxDli1vM%2BBcRXKemRo0sa%2BVJErJPZ%2Bwy5UHvUR4s%3D&reserved=0
>
> --
> Oscar
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutor&data=01%7C01%7Csydney.shall%40kcl.ac.uk%7C77fe088889364c79190308d61f4d4112%7C8370cf1416f34c16b83c724071654356%7C0&sdata=Benb%2BsxqZr1Rhdj8jG81KRurndfNVnBGx0%2B3z9VXd54%3D&reserved=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]
More information about the Tutor
mailing list