Numpy array multiple appropriation



  • code

    import numpy as np
    a = np.array([1, 2, 3])
    b = np.array([[1, 1], [0, 0]])
    c = np.array([[1], [2], [3]])
    np.savez( file, a=a, b=b, c=c )
    res = np.load( "file.npz" )
    print( res.files ) # ['a','b','c']
    a=res['a'] #[1 2 3]
    b=res['b'] #[[1 1],[0 0]]
    c=res['c'] #[[1],[2],[3]]
    

    I'd like for the kind.

    a,b,c=list(1,2,3)
    

    Whoever nibout can advise me how to correctly make multiple names in the mass, or in a cycle with the retraction of names from the body itself. I'd appreciate any clue.



  • Shorter version:

    a,b,c = np.load("file.npz").values()
    

    result:

    In [71]: a
    Out[71]: array([1, 2, 3])
    

    In [72]: b
    Out[72]:
    array([[1, 1],
    [0, 0]])

    In [73]: c
    Out[73]:
    array([[1],
    [2],
    [3]])



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2