I am aware that numpy arrays are pointer arrays. And I know that is possible to define pointers in python. But I am wondering, if I make a variable equal to an element in a numpy vector, is it still a pointer or is it de-referenced? Is there a way I can find out or test this?
Example
import scipy
vec = scipy.randn(10)
vecptr = vec # vecptr is a pointer to vec
vecval = scipy.copy(vec) # vecval is not a pointer.
var = vec[3] # is var pointer or is it copied by value ???
print(type(var)) # returns numpy.float64. does this mean its a 1x1 numpy vec and therefore a pointer ?
The reason I ask is, what I really want to know is; will the code below this double up my memory? I am trying to create more meaningful variable names to my vector that is returned
v = self.viewCoefs[sz][sv][sa]
gw = v[0]
G0 = v[1]
G1 = v[2]
G2 = v[3]
alpha0 = v[4]
alpha1 = v[5]
alpha2 = v[6]
beta0 = v[7]
beta1 = v[8]
beta2 = v[9]
beta3 = v[10]
gamma0 = v[11]
gamma1 = v[12]
gamma2 = v[12]
gamma3 = v[12]
gamma4 = v[13]
delta0 = v[14]
delta1 = v[15]
delta2 = v[16]
delta3 = v[17]
delta4 = v[18]
delta5 = v[19]
zeta_prime_0 = v[20]
zeta_prime_1 = v[21]
zeta_prime_2 = v[22]
Gamma_prime_0 = v[23]
Gamma_prime_1 = v[24]
Gamma_prime_2 = v[25]
Gamma_prime_3 = v[26]
Because I have lots of these to follow
p0 = alpha0 + alpha1*scipy.log(bfrac) + alpha2*scipy.log(bfrac)**2
p1 = beta0 + beta1*scipy.log(bfrac) + beta2*scipy.log(bfrac)**2 + beta3*scipy.log(bfrac)**3
p2 = gamma0 + gamma1*scipy.log(bfrac) + gamma2*scipy.log(bfrac)**2 + gamma3*scipy.log(bfrac)**3 + gamma4*scipy.log(bfrac)**4
p3 = delta0 + delta1*scipy.log(bfrac) + delta2*scipy.log(bfrac)**2 + delta3*scipy.log(bfrac)**3 + delta4*scipy.log(bfrac)**4 + delta5*scipy.log(bfrac)**5
subSurfRrs = g*(p0*u + p1*u**2 + p2*u**3 + p3*u**4)
## and lots more
So I would like meaningful variable names without doubling my memory foot print.
#
Okay, If I got it right, the solution to NOT double up my memory is :
v = self.veiwCoefs[sz][sv][sa]
gw = v[0:1]
G0 = v[1:2]
G1 = v[2:1]
alpha0 = v[3:4]
alpha1 = v[4:5]
alpha2 = v[5:6]
beta0 = v[6:7]
beta1 = v[7:8]
beta2 = v[8:9]
beta3 = v[9:10]
## etc
p0 = alpha0[0] + alpha1*scipy.log(bfrac) + alpha2[0]*scipy.log(bfrac)**2
p1 = beta0[0] + beta1[0]*scipy.log(bfrac) + beta2[0]*scipy.log(bfrac)**2 + beta3[0]*scipy.log(bfrac)**3
## etc
You almost have it, but here is how to create a view of a single element:
Here
ais a view of the fourth element ofv, so when you changeayou change the corresponding position inv.