の1つの配列を返す私はこのコードを持っている:私はstatをするためにstartp
関数を呼び出しています収量、ジェネレータオブジェクトを取り除く、代わりに3
:
import numpy as np
class B():
def __init__(self,a,b):
self.a = a
self.b = b
def __repr__(self):
return 'B({0},{1})'.format(self.a,self.b)
class test():
def __init__(self,name,method, measures=None):
self.name = name
self.method = method
self.measures = measures
def __repr__(self):
return 'test({0.name},{0.method},{1})'.format(self,self.measures)
def A(self,thevalues,another):
if self.method == 'S' and another != self.name:
yield self.S(thevalues)
if self.method == 'V':
yield self.V(thevalues)
def S(self, thevalues):
# Change thevalues and return the updated
thevalues = np.array(thevalues)
new_values = thevalues + 3
yield new_values
def V(self,thevalues):
yield thevalues
#return np.array(thevalues)
class basic():
def __init__(self, name, thelist):
self.name = name
self.thelist = thelist
def startp(self):
values = []
for i in self.thelist:
if i.name == self.name and i.method != 'S':
# Just fill some values to server as input to `A`
for j in range(4):
values.append(j)
# The `A` function will determine which functions inside
# `test` it will call
yield i.A(values,self.name)
まで、下からプロセス。
A
とS
の関数に渡すために、特定の条件(名前とメソッド)が満たされたときに、values
リストを初期化して入力しています。
次に、リスト内のすべてのオブジェクトに対してA
関数を呼び出すためにyieldを使用します。
A
機能は、特定の基準が満たされたときにS
またはV
機能をチェックして実行します。私はreturn np.array(thevalues)
を使用している場合、私は受け付けており、
b1 = np.array([B(1,2), B(3,4)])
b2 = np.array([B(5,6), B(7,8)])
b3 = np.array([B(9,10), B(11,12)])
alist = [ test('a','V',b1), test('b','S',b2), test('c','S',b3)]
obs = basic('a',alist).startp()
for i in obs:
for j in i:
print(j)
機能V
インサイド:
[0 1 2 3]
<generator object test.S at 0x7f74fc1c0b48>
[3 4 5 6]
<generator object test.S at 0x7f74fc1c0bf8>
[3 4 5 6]
私はyield thevalues
を使用している場合は、私が受けています:
<generator object test.V at 0x7f74ec99d678>
<generator object test.S at 0x7f74fc1c0bf8>
[3 4 5 6]
<generator object test.S at 0x7f74ec99d678>
[3 4 5 6]
このデータを使用して
しかし私が使用する場合:
for i in obs:
for j in i:
#print(j)
for k in j:
print(k)
私はV
生成された値にアクセスすることができますが、結果は次のとおりです。
[ [0 1 2 3],
[3 4 5 6],
[3 4 5 6]
]
:それは可能であれば私が欲しいもの
[0, 1, 2, 3]
[3 4 5 6]
3
4
5
6
[3 4 5 6]
3
4
5
6
は結果に一つだけの配列を受け取るために、ありますそして、私はstartp
に収穫明細を残す必要があります(基本的に1つの利回りは良いです、私はvalues
をS
に渡したいので、2つの利回りを使用します)
は、ご希望の出力は何ですか? '[0,1,2,3]'や '[3,4,5,6]'? – AsheKetchum
@AsheKetchum:投稿の終わりを確認してください。私は何の出力が必要なのかを書いています.1つの配列を私が言うようにしたいです。ありがとうございます – George
3アレイの配列ですか? – AsheKetchum