python - iterating over a tuple of iterables returned from a function -


  ci0 = np.random.randint (10, आकार = (15,)) uq, ix = np अद्वितीय (ci0, return_index = true): मैं, ज़िप में (यूके, ix) के लिए: print i, u   

क्या यह एक पंक्ति में एक अच्छा पायथनिक तरीका है? विशेष रूप से, np.unique (टपल के रूप में लौट आए) के परिणामों से दोहराएं।

ऐसा लगता है कि वहाँ होना चाहिए, लेकिन मैं सोच सकता था कि एकमात्र समाधान यह है, जो मुझे लगता है कि यह बहुत मुश्किल है सुरुचिपूर्ण:

  के लिए मैं, में np.transpose (np.unique (ci0, return_index = True)):    

आप उपयोग कर सकते हैं (splatting):

  ci0 = np.random.randint (10, आकार = (15,)) मैं, यू में ज़िप (* np.unique (ci0, return_index = True)): प्रिंट I, u   

बेहतर समझाने के लिए, निम्न कोड पर विचार करें:

  func (* (1, 2, 3))   

यह इसके बराबर है:

  func (1, 2, 3)    

Comments

Popular posts from this blog

c# - passing input text from view to contoller with FacebookContext using Facebook app -

ios - Does Core Data autoupdate a many to many relationship on saving -

Calling a C++ function from C# by passing a string with variable size to it -