Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Security violation using numpy.ix_ ?

Can we get this security block lifted please?

3 responses

I put that request into the issue tracker. Security changes tend to be a slower cycle than some other changes, but it will get there.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

@Simon I happen to know (and use) ix_ a fair bit. I've added it to the whitelist internally, but the change will take a view days to propagate.

For what it's worth, the definition of ix_ is pretty simple to rewrite:

In [74]: ix_??  # This doesn't work in research for security reasons, but you can use IPython locally to get the source of any callable.  
def ix_(*args):  
    """  
    Construct an open mesh from multiple sequences.

    This function takes N 1-D sequences and returns N outputs with N  
    dimensions each, such that the shape is 1 in all but one dimension  
    and the dimension with the non-unit shape value cycles through all  
    N dimensions.

    Using `ix_` one can quickly construct index arrays that will index  
    the cross product. ``a[np.ix_([1,3],[2,5])]`` returns the array  
    ``[[a[1,2] a[1,5]], [a[3,2] a[3,5]]]``.

    Parameters  
    ----------  
    args : 1-D sequences

    Returns  
    -------  
    out : tuple of ndarrays  
        N arrays with N dimensions each, with N the number of input  
        sequences. Together these arrays form an open mesh.

    See Also  
    --------  
    ogrid, mgrid, meshgrid

    Examples  
    --------  
    >>> a = np.arange(10).reshape(2, 5)  
    >>> a  
    array([[0, 1, 2, 3, 4],  
           [5, 6, 7, 8, 9]])  
    >>> ixgrid = np.ix_([0,1], [2,4])  
    >>> ixgrid  
    (array([[0],  
           [1]]), array([[2, 4]]))  
    >>> ixgrid[0].shape, ixgrid[1].shape  
    ((2, 1), (1, 2))  
    >>> a[ixgrid]  
    array([[2, 4],  
           [7, 9]])

    """  
    out = []  
    nd = len(args)  
    baseshape = [1]*nd  
    for k in range(nd):  
        new = _nx.asarray(args[k])  
        if (new.ndim != 1):  
            raise ValueError("Cross index must be 1 dimensional")  
        if issubclass(new.dtype.type, _nx.bool_):  
            new = new.nonzero()[0]  
        baseshape[k] = len(new)  
        new = new.reshape(tuple(baseshape))  
        out.append(new)  
        baseshape[k] = 1  
    return tuple(out)  
Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Yeah thanks, I did make my own version for now. For the curious, I am using a K-Medoids algorithm here:

https://github.com/salspaugh/machine_learning/blob/master/clustering/kmedoids.py