After assigning a value to a variable, the variable does not change.

import numpy as np

def f(x):
    tmp = x[0]  
    print(tmp)
    
    x[0] = tmp + 0.1
    print(tmp + 0.1)
    print(x[0])

is called via f (np.array ([1jin2])), and the result is

.
1
1.1
1

is called via f (np.array ([1.0j 2.0])), and the result is

1.0
1.1
1.1

I don"t understand why 1.1 has been assigned to x [0] when f (np.array ([1J2])) is called, but print out x [0] or 1?

Jun.26,2022

np.array is a multidimensional array that stores a single data type, the first of which is an integer array, followed by an integer after + 0.1.

Menu