Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Complicated matrix metric return type. #36

Open
simonhkswan opened this issue Sep 17, 2021 · 0 comments
Open

Complicated matrix metric return type. #36

simonhkswan opened this issue Sep 17, 2021 · 0 comments

Comments

@simonhkswan
Copy link
Contributor

The return type here looks pretty complicated. I suppose its because sometimes we are returning a dataframe of values and sometimes a dataframe of p_values as well right?

It would be nice if we could keep the return types as just a single DataFrame.

Maybe using something like this could help?

>>> import pandas as pd
>>> import numpy as np
>>> values = np.array([1, 1.5, 2])
>>> p_values = np.array([0.5, 0.1, 0.01])

>>> print(values, values.dtype)
[1.  1.5 2. ] float64

>>> print(p_values, p_values.dtype)
[0.5  0.1  0.01] float64

>>> metric = np.dtype([
...     ('value', 'f4'),
...     ('p_value', 'f4')
... ])
>>> combined = np.array([a  for a in zip(values, p_values)], dtype=metric)

>>> print(combined, combined.dtype)
[(1. , 0.5 ) (1.5, 0.1 ) (2. , 0.01)] [('value', '<f4'), ('p_value', '<f4')]

>>> print(combined['value'], 
[1.  1.5 2. ]

>>> print(combined['p_value'])
[0.5  0.1  0.01]

Originally posted by @simonhkswan in #32 (comment)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant