Tensorflow:沿指定维度的索引

时间:2016-11-19 17:32:50

标签: tensorflow

遗憾的是,以下代码在Tensorflow中不起作用:

public class PagesList extends Activity {
        ListView listView;
        public List<Person> persons;

        class Person {
            String name;
            String age;


            Person(String name, String age) {
                this.name = name;
                this.age = age;

            }

            @Override
            public String toString() {
                return this.name;
            }
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_pages_list);


             listView = (ListView) findViewById(R.id.PagesList);
            persons = new ArrayList<>();

            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView parent, final View view, int position, long id) {
                    Toast toast = Toast.makeText(getApplicationContext(), persons.get(position).age.toString(), Toast.LENGTH_LONG);
                    toast.show();
                            }


            });


            /* make the API call */
            new GraphRequest(
                    AccessToken.getCurrentAccessToken(),
                    "/me/accounts",
                    null,
                    HttpMethod.GET,
                    new GraphRequest.Callback() {
                        public void onCompleted(GraphResponse response) {
                /* handle the result */

                            try {
                                JSONArray data = response.getJSONObject().optJSONArray("data");
                                for (int i = 0; i < data.length(); i++) {
                                    JSONObject oneAlbum = data.getJSONObject(i);

                                    //get your values    

                                    persons.add(new Person(oneAlbum.getString("name"), oneAlbum.getString("id")));

                                }

                                ShowPageList();

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }


                        }
                    }
            ).executeAsync();


        }

        public void ShowPageList(){
            ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, persons);
            listView.setAdapter(adapter);

        }

    }

所以id_translation操作选择索引,这个数字应该用于索引另一个张量。我看了tf.gather但不知道如何使用它,我认为这应该是相对简单的。关于如何进行索引的建议?

编辑: 我做了一个小代码示例来重现问题:

id_translation = tf.argmax(z_pi_translation,1)
translations = z_mu_translation[:,id_translation,:]

1 个答案:

答案 0 :(得分:0)

尝试tf.slice(z_mu_translation, tf.concat(0, [[0], id_translation], [0]), [-1, -1, -1])

相关问题