Decision Optimization

 View Only
Expand all | Collapse all

Creating an ndarray from ragged nested sequences(which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths / shapes)is deprecated

  • 1.  Creating an ndarray from ragged nested sequences(which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths / shapes)is deprecated

    Posted Mon August 22, 2022 09:31 AM
    Edited by System Test Fri January 20, 2023 04:23 PM
    Dear All,
    I need to create a nested array before creating a constraint in the CPLEX library. Here is the code.
        A = np.array([1,2,3,[1,3]])
    A.astype(dtype = object)
    p = np.array([40,100,70])
    c = np.array([20,100,120])
    v = 3
    w = 5

    for i, idx in enumerate(A):
    # get z and c
    z_lst = z[np.array(idx)-1]
    c_lst = c[np.array(idx)-1]

    # constraint
    mdl.add_constraint(1 + np.sum(z_lst) >= y * ((n + 1 - 2 * (len(A))) * (2 * v + 2 * w) + np.sum((2 * w + v + c_lst))))

    Error notification:

    C:/Users/pknu/Documents/Research/project/Final Code/Marking Optimization Single Arm - 3 steps.py:10: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. A = np.array([1,2,3,[1,3]])

    image.png
    Could anyone tell me what should I do, please? Thank you in advance.
    Best regards,
    Nicholas

    #DecisionOptimization


  • 2.  RE: Creating an ndarray from ragged nested sequences(which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths / shapes)is deprecated

    Posted Mon August 22, 2022 10:45 AM
    Dear Nicholas,
    The issue you are reporting is a numpy error.
    Is it required to make 'A' variable a numpy array  (instead, one could use a python list: `A = [1, 2, 3, [1, 3]]`?
    If this is the case, with the version of numpy you are using, it looks like the required syntax is:
    A = np.array([1 ,2 ,3 ,[1 ,3]], dtype=object)
    I hope this helps.
    Best regards,
    Hugues

    ------------------------------
    Hugues Juille
    ------------------------------



  • 3.  RE: Creating an ndarray from ragged nested sequences(which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths / shapes)is deprecated

    Posted Mon August 22, 2022 09:10 PM
    Dear Hugues,

    Thank you, it worked!

    Best regards,
    Nicholas