2013-07-19 2 views
0

저는 프로그래밍에 익숙하지 않아 내 프로그램에 대한 도움을 주시면 감사하겠습니다. 내가 for 루프를 통해 배열에 읽어 그들에 대한 몇 가지 계산을하고 3D 그래프에 결과를 플롯하기 위해 노력하고있어,하지만 나에게 오류 제공 :배열을 반복하면서 배열에서 계산을 수행하고 결과를 플로팅 하시겠습니까?

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt 
import numpy as np 
import math 
from itertools import product, combinations 
from numpy import * 
fig = plt.figure() 
ax = fig.gca(projection='3d') 
ax.set_aspect("equal") 

ra_day = loadtxt("RA Days.txt") 
ra_minute = loadtxt("RA Minutes.txt") 
ra_second = loadtxt("RA Seconds.txt") 
ra = ra_day + (ra_minute/60) + (ra_second/3600) 

dec_day = loadtxt("DEC Days.txt") 
dec_minute = loadtxt("DEC Minutes.txt") 
dec_second = loadtxt("DEC Seconds.txt") 
dec = dec_day + (dec_minute/60) + (dec_second/3600) 

dist = loadtxt("Distance.txt") 

for i in range(len(ra)): 
    x = math.cos(ra[i]) * (dist[i] * math.cos(dec[i])) 
    y = math.sin(ra[i]) * (dist[i] * math.cos(dec[i])) 
    z = dist * math.sin(dec[i]) 

ax.scatter([0],[0],[0],color="b",s=100) 
ax.scatter([x],[y],[z],color="k",s=100) 

plt.show() 
: 여기

IndexError: index 753 is out of bounds for axis 0 with size 753 

하면 코드의

+1

아마도'ra'와'dec'는 같은 길이가 아닙니다. – roippi

+0

그들은 둘 다 길이 754입니다. –

+0

괜찮아요.하지만 이제는 "TypeError : type int '의 객체에 len()이 없습니다. 심지어 ra, dec 및 dist의 길이가 753 –

답변

0

언어를 모르지만 일반적으로 범위를 벗어나는 인덱스는 시작 및 종료 인덱스가 올바르지 않은 경우입니다. length-1 대신 길이가 0이 될 때까지 시작합니다. 특히 언어를 아는 사람이 답변을 게시 할 때까지는 그 값어치가 있습니다. 희망이 도움이되었을 수도 있습니다

관련 문제