我有下面的代码。
import numpy as np
from scipy.interpolate import interp1d
stream = "350.51 0.37, 352.19 0.37, 353.87 0.37, 355.55 0.37, 357.22 0.37, 358.9 0.37, 360.57 0.37, 362.24 0.37, 363.91 0.37, 365.58 0.37, 367.24 0.37, 368.91 0.37, 370.57 0.38, 372.24 0.38, 373.9 0.38, 375.56 0.38, 377.22 0.38, 378.88 0.38, 380.53 0.38, 382.19 0.38, 383.85 0.39, 385.5 0.39, 387.15 0.39, 388.81 0.39, 390.46 0.39, 392.11 0.39, 393.76 0.39, 395.41 0.39, 397.06 0.39, 398.7 0.39, 400.35 0.39, 402.0 0.39, 403.64 0.39, 405.29 0.39, 406.93 0.39, 408.58 0.4, 410.22 0.4, 411.86 0.4, 413.51 0.4, 415.15 0.4, 416.79 0.4, 418.43 0.4, 420.07 0.4, 421.71 0.4, 423.35 0.4, 424.99 0.4, 426.63 0.4, 428.27 0.41, 429.91 0.41, 431.54 0.41, 433.18 0.41, 434.82 0.41, 436.46 0.41, 438.09 0.41, 439.73 0.41, 441.37 0.41, 443.0 0.41, 444.64 0.41, 446.27 0.41, 447.91 0.41, 449.54 0.41, 451.18 0.41, 452.81 0.41, 454.45 0.42, 456.08 0.42, 457.72 0.42, 459.35 0.42, 460.99 0.42, 462.62 0.42, 464.26 0.42, 465.89 0.42, 467.52 0.42, 469.16 0.42, 470.79 0.42, 472.42 0.42, 474.06 0.42, 475.69 0.42, 477.32 0.42, 478.96 0.42, 480.59 0.43, 482.22 0.43, 483.86 0.43, 485.49 0.43, 487.12 0.43, 488.76 0.43, 490.39 0.43, 492.02 0.43, 493.65 0.43, 495.29 0.43, 496.92 0.43, 498.55 0.43, 500.18 0.43, 501.82 0.44, 503.45 0.44, 505.08 0.44, 506.71 0.44, 508.35 0.44, 509.98 0.44, 511.61 0.44, 513.24 0.44, 514.88 0.44, 516.51 0.44, 518.14 0.44, 519.77 0.44, 521.4 0.44, 523.03 0.44, 524.67 0.44, 526.3 0.44, 527.93 0.44, 529.56 0.45, 531.19 0.45, 532.82 0.45, 534.45 0.45, 536.09 0.45, 537.72 0.45, 539.35 0.45, 540.98 0.45, 542.61 0.45, 544.24 0.45, 545.87 0.45, 547.5 0.45, 549.13 0.45, 550.76 0.45, 552.39 0.45, 554.02 0.45, 555.65 0.45, 557.28 0.45, 558.91 0.45, 560.54 0.45, 562.16 0.45, 563.79 0.45, 565.42 0.45, 567.05 0.45, 568.68 0.45, 570.31 0.45, 571.93 0.45, 573.56 0.45, 575.19 0.45, 576.81 0.45, 578.44 0.45, 580.07 0.45, 581.69 0.46, 583.32 0.46, 584.94 0.46, 586.57 0.46, 588.19 0.46, 589.82 0.46, 591.44 0.46, 593.07 0.46, 594.69 0.46, 596.31 0.46, 597.94 0.46, 599.56 0.46, 601.18 0.46, 602.8 0.46, 604.42 0.46, 606.05 0.46, 607.67 0.46, 609.29 0.46, 610.91 0.46, 612.53 0.46, 614.14 0.46, 615.76 0.46, 617.38 0.46, 619.0 0.46, 620.62 0.46, 622.23 0.46, 623.85 0.46, 625.47 0.46, 627.08 0.46, 628.7 0.46, 630.31 0.46, 631.93 0.46, 633.54 0.45, 635.15 0.45, 636.77 0.46, 638.38 0.45, 639.99 0.45, 641.6 0.45, 643.21 0.45, 644.82 0.45, 646.43 0.45, 648.04 0.45, 649.65 0.45, 651.26 0.45, 652.86 0.45, 654.47 0.45, 656.08 0.45, 657.68 0.45, 659.29 0.45, 660.89 0.45, 662.5 0.45, 664.1 0.45, 665.7 0.45, 667.3 0.45, 668.91 0.45, 670.51 0.45, 672.11 0.45, 673.71 0.45, 675.3 0.45, 676.9 0.45, 678.5 0.45, 680.1 0.45, 681.69 0.45, 683.29 0.45, 684.88 0.45, 686.48 0.45, 688.07 0.45, 689.66 0.45, 691.26 0.45, 692.85 0.45, 694.44 0.45, 696.03 0.45, 697.62 0.45, 699.21 0.45, 700.79 0.45, 702.38 0.45, 703.97 0.45, 705.55 0.45, 707.14 0.45, 708.72 0.45, 710.31 0.45, 711.89 0.45, 713.47 0.45, 715.05 0.45, 716.63 0.45, 718.21 0.45, 719.79 0.45, 721.37 0.45, 722.95 0.45, 724.53 0.45, 726.1 0.45, 727.68 0.45, 729.25 0.45, 730.83 0.45, 732.4 0.45, 733.97 0.45, 735.54 0.45, 737.11 0.45, 738.68 0.45, 740.25 0.45, 741.82 0.45, 743.39 0.45, 744.96 0.45, 746.52 0.45, 748.09 0.45, 749.65 0.45, 751.22 0.45, 752.78 0.45, 754.35 0.45, 755.91 0.45, 757.47 0.45, 759.03 0.45, 760.59 0.45, 762.15 0.45, 763.71 0.45, 765.26 0.45, 766.82 0.45, 768.38 0.45, 769.93 0.45, 771.48 0.45, 773.04 0.45, 774.59 0.45, 776.14 0.45, 777.7 0.45, 779.25 0.45, 780.8 0.45, 782.35 0.45, 783.89 0.45, 785.44 0.45, 786.99 0.44, 788.54 0.44, 790.08 0.45, 791.63 0.45, 793.17 0.44, 794.71 0.44, 796.26 0.44, 797.8 0.44, 799.34 0.44, 800.88 0.44, 802.42 0.44, 803.96 0.44, 805.5 0.44, 807.04 0.44, 808.58 0.44, 810.11 0.44, 811.65 0.44, 813.19 0.44, 814.72 0.44, 816.25 0.44, 817.79 0.44, 819.32 0.44, 820.85 0.44, 822.39 0.44, 823.92 0.44, 825.45 0.44, 826.98 0.44, 828.51 0.44, 830.03 0.44, 831.56 0.44, 833.09 0.44, 834.62 0.44, 836.14 0.44, 837.67 0.44, 839.19 0.44, 840.72 0.44, 842.24 0.44, 843.77 0.44, 845.29 0.44, 846.81 0.44, 848.33 0.44, 849.86 0.44, 851.38 0.44, 852.9 0.44, 854.42 0.44, 855.94 0.44, 857.45 0.44, 858.97 0.44, 860.49 0.44, 862.01 0.44, 863.52 0.44, 865.04 0.44, 866.56 0.44, 868.07 0.44, 869.59 0.44, 871.1 0.44, 872.62 0.44, 874.13 0.44, 875.64 0.44, 877.16 0.43, 878.67 0.44, 880.18 0.43, 881.69 0.43, 883.2 0.44, 884.71 0.43, 886.22 0.44, 887.73 0.43, 889.24 0.43, 890.75 0.43, 892.26 0.43, 893.77 0.43, 895.28 0.43, 896.79 0.43, 898.29 0.43, 899.8 0.43, 901.31 0.43, 902.81 0.43, 904.32 0.43, 905.83 0.43, 907.33 0.43, 908.84 0.43, 910.34 0.43, 911.85 0.43, 913.35 0.43, 914.85 0.43, 916.36 0.43, 917.86 0.43, 919.36 0.43, 920.87 0.43, 922.37 0.43, 923.87 0.43"
stream = stream.split(",")
stream = np.asarray(stream)
refa = []
wava = []
for rec in stream:
sa = np.fromstring(rec, sep=' ')
refa.append(sa[1])
wava.append(sa[0])
f = interp1d(wava,refa)
fitrefa = f(np.arange(wava[0],wava[-1],5))
'stream'是由用户以这种格式给出的。(这里我已经给出了这个值作为参考)。
# following is the output when I print refa and fitrefa:
refa = [0.37, 0.37, 0.37, 0.37, 0.37, 0.37, 0.37, 0.37, 0.37, 0.37, 0.37, 0.37, 0.38, 0.38, 0.38, 0.38, 0.38, 0.38, 0.38, 0.38, 0.39, 0.39, 0.39, 0.39, 0.39, 0.39, 0.39, 0.39, 0.39, 0.39, 0.39, 0.39, 0.39, 0.39, 0.39, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.42, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.46, 0.45, 0.45, 0.46, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.44, 0.44, 0.45, 0.45, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.44, 0.43, 0.44, 0.43, 0.43, 0.44, 0.43, 0.44, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43, 0.43]
fitrefa = [0.37 0.37 0.37 0.37 0.37963855 0.38
0.38 0.39 0.39 0.39 0.39 0.39
0.4 0.4 0.4 0.4 0.41 0.41
0.41 0.41 0.41 0.42 0.42 0.42
0.42 0.42 0.4295092 0.43 0.43 0.43
0.4320122 0.44 0.44 0.44 0.44 0.44
0.45 0.45 0.45 0.45 0.45 0.45
0.45 0.45 0.45 0.45 0.45271605 0.46
0.46 0.46 0.46 0.46 0.46 0.46
0.46 0.46 0.46 0.45222222 0.45 0.45
0.45 0.45 0.45 0.45 0.45 0.45
0.45 0.45 0.45 0.45 0.45 0.45
0.45 0.45 0.45 0.45 0.45 0.45
0.45 0.45 0.45 0.45 0.45 0.45
0.45 0.45 0.45 0.44954839 0.45 0.44
0.44 0.44 0.44 0.44 0.44 0.44
0.44 0.44 0.44 0.44 0.44 0.44
0.44 0.44 0.44 0.44 0.43 0.43529801
0.43 0.43 0.43 0.43 0.43 0.43
0.43 ]
我想在dart中复制这种行为并得到fitrefa值。
1条答案
按热度按时间qyswt5oh1#
以下代码可以正常工作:
我创建了一个interp1d(),并使用简单的数学公式计算直线。