如何用标量乘以Keras张量?

时间:2018-02-22 23:44:40

标签: keras tensor

如果我有张量,public class MainActivity extends BaseActivity { private static final String TAG = MainActivity.class.getSimpleName(); private RecyclerView playersRV; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); authStateListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { FirebaseUser user = firebaseAuth.getCurrentUser(); if (user == null){ Log.d(TAG, "User is null"); startActivity(new Intent(MainActivity.this, LoginActivity.class)); } else { Log.d(TAG, "User exists:\t" + user.getEmail()); return; } } }; playersRV.setHasFixedSize(true); playersRV.setLayoutManager(new LinearLayoutManager(this)); findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mAuth.signOut(); mAuth = null; startActivity(new Intent(MainActivity.this, LoginActivity.class)); } }); } private void init() { playersRV = findViewById(R.id.playersRV); } @Override protected void onStart() { super.onStart(); if (authStateListener == null){ mAuth.addAuthStateListener(authStateListener); } } @Override protected void onStop() { super.onStop(); if (authStateListener != null){ mAuth.removeAuthStateListener(authStateListener); authStateListener = null; } } } v,我知道你可以将它们与

相乘
w

但是如果我想用标量乘以a = Multiply()([v, w]) v怎么办?

2 个答案:

答案 0 :(得分:2)

您可以将Lambda层用于其他任何标量操作

标量乘法

res5 = Lambda(lambda x: x * 3)(res4)

标量添加

res5 = Lambda(lambda x: x + 4)(res4)

答案 1 :(得分:0)

如果您使用tensorflow作为后端,则支持*运算符(请参阅this answer)。

a = v * 0.10