substitution into Python array

Asked 1 years ago, Updated 1 years ago, 55 views

I am using python 2.7.
Now execute the code below and

printr.data
printer[0][action-1].data

[[0.346424640.39359313-1.24270797-0.899237990.11451679-0.49929592]]
- 0.499295920134

the result came out.So,

r[0][action-1].data=1

Even if I substitute for you,

 printer[0][action-1].data

- 0.499295920134

The substitution is not reflected.What's the problem?
Thank you.
The import packages are as follows:

import numpy as np        
import matplotlib.pyplot asplt
import cv2
import random
import chain
from chain import cuda
from chain import serializers
import chain.functions as F
from chain import optimizers

Also, if you enter print(type(r)),

class'chain.variable.Variable'

and printr.dtype The result is

float32

That's right. Nice to meet you.

python chainer

2022-09-30 21:24

1 Answers

r[0] invokes https://github.com/chainer/chainer/blob/master/chainer/functions/array/get_item.py#L67.
A FunctionNode called GetItem is created and the apply method is called by r as an argument.
In other words, the original Variable does not share the data because it asks you to create and apply a computational node called slice.

If you want to rewrite it

r.data[0][1] = 0.0

I guess so.
It is rewritten to what the CPU is running.I don't know if it's a GPU (that is, if the data is cupy.ndarray).

If you're not saying you've tried it for a while, I thought you'd better give the Chains community the question "Why do you want to do it?"


2022-09-30 21:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.