Python初学者,恳请大家帮助看看是啥问题所在呢?非常感谢
在Google Colab环境里运行Python程序,直接打印整个字典{}没有问题vertices和faces合在一起可以都打印出来。但是单独打印字典中的vertice和faces,表面上看到,vertices可以打印出来,faces却无法print出来。然而用controlF可以发现faces的output,但是没有真正地print显示出来,好像被隐藏了一样。print(facesList[:76156])这样的话可以看到print出来从0到第76156个output,然而print(facesList[:76157])这样的话就看不到print出来的结果,print(facesList)也看不到print出来的结果,好像被隐藏了一样。
统计facesList一共是85262个output,打印到76156可以看到输出的结果,但是到76157却看不到任何输出的结果了。统计verticesList一共是22269个output。
不知道为啥在Google Colab环境里面运行就有问题,其他环境就ok。
请别人帮助在jupyter notebook打开程序运行,可以看到单独faces打印出来的结果。
下面是代码,恳请大家帮助看看是啥问题所在呢?非常感谢
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
def plot_point_cloud(verts):
verts = np.array(verts)
fig = plt.figure(figsize=(5, 5))
ax = Axes3D(fig, azim=-90, elev=0)
ax.scatter3D(
verts[:, 0],
verts[:, 2],
verts[:, 1]
)
ax.set_xlabel('x')
ax.set_ylabel('z')
ax.set_zlabel('y')
plt.show()
import requests
def get_dictionary_from_obj():
obj = requests.get("https://raw.githubusercontent.com/porterjenkins/cs180-intro-data-science/master/data/plane.obj")
dta = obj.text.splitlines()
pointcloud = {}
verticesList = []
facesList = []
for row in dta:
currentRow = row.split()
if currentRow[0] == "v": # vertices
floatList = [float(i) for i in currentRow[1:]]
verticesList.append(floatList)
elif currentRow[0] == "f": # faces
if "/" in row:
intList = []
for i in range(1, len(currentRow)):
target = currentRow[i]
slashIndex = target.find("/")
slash = target[:slashIndex]
intList.append(int(slash))
else:
intList = [int(i) for i in currentRow[1:]]
facesList.append(intList)
#facesList.append(str(intList))
pointcloud["vertices"] = verticesList
pointcloud["faces"] = facesList
#print(facesList[:76156])
return pointcloud
pointcloud = get_dictionary_from_obj()
print("pointcloud = {")
print(pointcloud) # please control F for 'faces', very sorry, really appreciate your kind and help very much
#print("v:")
#print(poincloud["vertices"])
#print("f:")
#print(poincloud["faces"])
print("}")
plot_point_cloud(pointcloud["vertices"])
在Google Colab运行,单独Faces打印,出现output不显示的问题
请别人帮助在jupyter notebook打开程序运行,可以看到单独faces打印出来的结果。