我接受輸入處理并將其存盤在列格式(4 * 1 陣列)中,然后將其放入(4 * n np.zero 陣列)中。回圈此以獲得 n 個輸入
import numpy as np
l= int(input("enter the no. of elements"))
print ("enter the co-ordinates (X Y Z)-space seperated ")
i=0
inpf=np.zeros([4,(l)])
while(i<l):
inp1=np.array(input().split(" "))
inp2=[int(j) for j in inp1]
inp3=np.append(inp2,[1],axis=0)
inp=np.atleast_2d(inp3).T
inpf[:,i]=inp
i=i 1
print(inf)
此代碼不起作用(錯誤-inpf[:,i]=inp ValueError: could not broadcast input array from shape (4,1) into shape (4,))
我該如何解決這個錯誤?如何使代碼更節省空間?
謝謝
uj5u.com熱心網友回復:
嘗試更簡單的串列方法
inp1=input().split(" ")
inp2=[int(j) for j in inp1]
inp2.append(1)
inpf[:,i]=inp2
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/507387.html