Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

numpy - Rookie Python-questions, array indexing issue


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Couple of errors, you are missing a ] on xyz[y, x, new[idx]] = new[idx]. Put that back in and it should fix one error.

Also in python if you want to use try, you need to have an except clause. If you don't want it, you can just have an empty pass statement in there.

# pre-define
import numpy as np
import matplotlib.pyplot as plt

# from txt to array
file = ('..locationdata.TXT')

# 2D data in value
data2D = np.loadtxt(file, delimiter='')

# 1D data in array
data1D = digits.flatten()

# width / height
w = data2D.shape[0]
h = data2D.shape[1]

# try to convert to 3d array[X,Y,depth]
try:
    for y in range(0, h):
        for x in range(0, w):
            idx = y * w + x
            xyz[y, x, new[idx]] = new[idx]
except:
    pass

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...