मैं numpy ndarray subclass करना चाहता हूँ। हालांकि, मैं सरणी नहीं बदल सकता। क्यों self = ...
सरणी नहीं बदलता है? धन्यवाद।उप-वर्गीकरण numpy ndarray समस्या
import numpy as np
class Data(np.ndarray):
def __new__(cls, inputarr):
obj = np.asarray(inputarr).view(cls)
return obj
def remove_some(self, t):
test_cols, test_vals = zip(*t)
test_cols = self[list(test_cols)]
test_vals = np.array(test_vals, test_cols.dtype)
self = self[test_cols != test_vals] # Is this part correct?
print len(self) # correct result
z = np.array([(1,2,3), (4,5,6), (7,8,9)],
dtype=[('a', int), ('b', int), ('c', int)])
d = Data(z)
d.remove_some([('a',4)])
print len(d) # output the same size as original. Why?
कृपया अपने अपेक्षित आउटपुट प्रदान करें, यह स्पष्ट नहीं है कि आप क्या हासिल करना चाहते हैं। –
मैं डेटा उदाहरण से पंक्तियों को हटाना चाहता हूं। – riza
ठीक है, आप एक मुखौटा का उपयोग कर सकते हैं, लेकिन अगर आप एक और सवाल पूछते हैं तो बेहतर है क्योंकि इसे ndarray –