Replacement of # array of the program g → 0 not included g2 → 0 included unit
Line 111
I want to insert the first 500 pieces of an array (iso0) with 1001 pieces after the second half 500 pieces.
(Put the function set at 500 ^ 120500 ^ 12 in time as a periodic function in the array of 0500 ^ 121000 ^ 12)
(Before conversion 500 ^ 12 ~ 1 ^ 12, 0, 1 ^ 12 ~ 500 ^ 12
(After conversion 0, 1 ^ 12 ~ 500 ^ 12, 500 ^ 12 ~ 1 ^ 12
Traceback (most recent call last):
File "C: \ Users \ oreka \ python \ 2jigen3.py", line 115, in
iso0g [i] = iso0 [i + 501]
TypeError: can only concatenate tuple (not "int") to tuple
import numpy as np
import math
import matplotlib.pyplot as plt
#Constant declaration
a = np.arange (500.0e12,600.0e12,1.0e12) # 500.0e12 ~ 600.0e12 time t (1100 elements)
a2 = np.arange (1,1000,1) # 1 to 1000 integers (used to assign lines with 3 elements in one line of k)
a3 = np.arange (500.0e12500.0e12,1.0e12) # 500.0e12 to 500.0e12 time t (1001 elements)
a4 = np.arange (0,1000.0e12,1.0e12) #Time for graph t
iso0g = np.arange (0,1001,1.0) # Insertion after sequence replacement
isog = np.arange (0,1001,1.0) # Insertion after array replacement
iso2g = np.arange (0,1001,1.0) # Insertion after sequence replacement
g = np.arange (0,500,1.0) # 0 not included
g2 = np.arange (501,1001,1.0) # 0 included
k = np.eye (1001) #k base (identity matrix (1001 × 1001))
A = 100
B = 217.0e28
z = 30.0e + 3
T = 18016836.0e18
dz = 15000
Creating #p (t, z) and dp/dz
p = pow (A * T, 2)/np.sqrt (pow (T, 4) + pow (B * z, 2)) * np.exp ((1 * pow (T * a, 2))/(pow (T, 4) + pow (B * z, 2)))
#p (a3 size)
pa3 = pow (A * T, 2)/np.sqrt (pow (T, 4) + pow (B * z, 2)) * np.exp ((1 * pow (T * a3, 2))/(pow (T, 4) + pow (B * z, 2)))
# p1a3 (t + dz)
p1a3 = pow (A * T, 2)/np.sqrt (pow (T, 4) + pow (B * (z + dz), 2)) * np.exp ((1 * pow (T * a3,)) 2))/(pow (T, 4) + pow (B * (z + dz), 2)))
# p2a3 (tdz)
p2a3 = pow (A * T, 2)/np.sqrt (pow (T, 4) + pow (B * (z dz), 2)) * np.exp ((1 * pow (T * a3,)) 2))/(pow (T, 4) + pow (B * (z dz), 2)))
dpdz = pow (A * T * B, 2) * z * ((2 * pow (T * a3,2))/(pow (T, 4) + pow (B * z, 2)) ―― 1) * pow (pow (T, 4)
+ pow (B * z, 2), 1.5) * np.exp (1 * pow (T * a3,2)/(pow (T, 4) + pow (B * z, 2)))
pp = (p1a3 pa3)/dz # forward difference
pp2 = (p1a3 p2a3)/2/dz # center difference
Transform the # dp/dz matrix into a vertical column
dpdz = dpdz.reshape ([1001,1])
pp = pp.reshape ([1001,1])
pp2 = pp2.reshape ([1001,1])
Repeatedly assign p to rows 2 to 1000 of #k (identity matrix (1001 x 1001)) * Rows with 3 elements in one rowfor i in a2:
k [i] [i1] = p [i + 1] + p [i + 2]
k [i] [i] =(p [i + 1] + 2 * p [i + 2] + p [i + 3])
k [i] [i + 1] = p [i + 2] + p [i + 3]
Substitute p in the 1st and 1001st lines of #k * A line with 2 elements in one line
k [1000] [1000] =(p [1001] + 2 * p [1002] + p [1003])
k [1000] [999] = p [1001] + p [1002]
k [0] [0] =(p [1] + 2 * p [2] + p [3])
k [0] [1] = p [2] + p [3]
kin = np.linalg.inv (k) Inverse matrix kin of #k
b = dpdz/dz/B # creation and b (dpdz) creation
b2 = pp/dz/B # b2 (forward difference)
b3 = pp2/dz/B # b3 (center difference)
#For checking how many elements are contained in each array (shape)
"" "
print ("a")
print (a.shape)
print ("a2")
print (a2.shape)
print ("a3")
print (a3.shape)
print ("k")
print (k.shape)
print ("p")
print (p.shape)
print ("dpdz")
print (dpdz.shape)
print ("kin")
print (kin.shape)
"" "
# For confirmation of each matrix (shape)
np.set_printoptions (linewidth = 2000, edgeitems = 7, precision = 4, floatmode ='maxprec')
print ("k")
print (k)
print ("p")
print (p)
print ("dpdz")
print (dpdz)
print ("b")
print (b)
print ("kin")
print (kin)
Calculate φ from the formula # 3.13
iso0 = kin @ b # iso0 b = dpdz
iso0 = iso0.reshape ([1001,])
print ("iso0")
print (iso0.shape)print (iso0)
iso = kin @ b2 # iso b = forward difference
iso = iso.reshape ([1001,])
print ("iso")
print (iso.shape)
print (iso)
iso2 = kin @ b3 # iso2 b = center difference
iso2 = iso2.reshape ([1001,])
print ("iso2")
print (iso2.shape)
print (iso2)
#Swap array g → 0 not included g2 → 0 included
for i in enumerate (g):
iso0g [i] = iso0 [i + 501]
isog [i] = iso [i + 501]
iso2g [i] = iso2 [i + 501]
for i in g2:
iso0g [i] = iso0 [i501]
isog [i] = iso [i501]
iso2g [i] = iso2 [i501]
#iso for confirmation
print ("iso0")
print (iso0g)
print (iso0g.shape)
#PLOt of each matrix
plt.figure (0)
plt.xlabel ("t")
plt.ylabel ("p (t, z)")
plt.plot (a, p)
plt.figure (1)
plt.xlabel ("t")
plt.ylabel ("b and pp")
plt.plot (a3, dpdz)
plt.plot (a3, pp)
plt.plot (a3, pp2)
plt.figure (2)
plt.xlabel ("t")
plt.ylabel ("φ")
plt.plot (a4, iso0g)
plt.plot (a4, isog)
plt.plot (a4, iso2g)
plt.show ()
What I tried
I fixed it when I got an error before (make it float type), but after that it does not work
Supplementary information (FW/tool version, etc.)Please provide more detailed information here.

Answer # 1

Answer # 2
Two corrections are required.
First of all, in the following, g and g2 need to be ints used in the loop, so adding .0 is not good for float.
g = np.arange (0,500,1.0) # 0 not included g2 = np.arange (501,1001,1.0) # 0 included
Revised
g = np.arange (0,500,1) # 0 not included g2 = np.arange (501,1001,1) # 0 included
Next, you don't need enumerate () in the following places. i becomes a tuple.
#Swap array g → 0 not included g2 → 0 included for i in enumerate (g):
Revised
#Swap array g → 0 not included g2 → 0 included for i in g:
Related articles
 python  i want to swap the first half and the second half of the array and put them in different arrays
 it's the second day of programming for the first time tell us about javascript
 i want to make a python array onedimensional, but it doesn't work
 python  regarding the problem that the length of a list with a different name is also affected by the code that searches while
 python  i want to store an object in an array
 how to use python 2d array
 is it possible to determine if today is the first weekday of the week starting on monday? : python
 about for syntax i want to know the reason why the result is different depending on where the initial value is defined python
 python  handling of 1d array data when using the predict function in keras
 python: an error occurs that the type is different in the output using dict key values
 python 3x  the program only works on the first line
 i want to display screens with different window sizes when i press the [python/tkinter] tab
 python  typeerror when calculating the array of images called by imageopen ()
 python  array elements cannot be used as function arguments ??
 i want to get an array of directory names and file names in python and create a csv
 python  i want to get only the value of the first stage (after roipool) of faster rcnn of torchvision
 python  i want to store a 3d array in an array using numpy
 python  i want to get the very first value of the corresponding condition in the time condition of pandas
 i want to convert "array string" to an array in python
 python : In the Keras CNN, the input array and the target (teacher) array does not match
 python : How to create a second one on a column that will reflect the content of the first?
 python : There are numbers in order, but with skipping. How to get intervals?
 python : Sort positive and negative values within the variable
 Trust intervals for regression model parameters in Python
 python : How to find points functions
 python : Randomly retrieve data from the list and make a new data list
 python : ITERATOR GLOBAL FLAGS MUST BE A LIST OR TUPLE OF STRINGS ERROR
 Python Numpy Sort
 Scikit Learn Python
If you just need to prepare a box to put the calculated result
numpy.empty ()
Is recommended.You should be aware of what type will be included.
You can make one loop by switching the first half and the second half as follows. (Boundary handling is probably wrong in the originally written code)
In addition, numpy has a handy function to do this,
numpy.roll ()
With functions, you don't need to loop or prepare a box in advance.