python的toarray
A. java中Collection方法裡面的Object[] toArray() 和 <T> T[] toArray(T[] a)有什麼區別嗎
<T> T[] toArray(T[] a):返回包含此 collection 中所有元素的數組;返回數組的運行時類型與指定數組的運行時類型相同
也就是說此方法可以指定返回數組中的對象類型
toArray(new Object[0]) 和 toArray() 在功能上是相同的
B. JAVA中ArrayList的toArray()方法要怎麼用
import java.util.ArrayList;
public class Test40023{
public static void main(String args[]){
ArrayList<Integer> a = new ArrayList<Integer>();
a.add(1);
a.add(2);
for(int i =0;i < a.size();i++){
System.out.println(a.toArray()[i]);
}
}
}
運行結果:
1
2
——-------------------
toArray()方法是指將ArrayList轉換為數組,如上述例子所示
C. java 中關於toArray()方法的問題
包含所有的對象就是list中的所有對象(ste1、2、3、4),指定類型就是list中的那些對象的類型,這里是String。入口參數就是要給與你調用的方法的變數,例如: System.out.println(Arrays.asList(strs2)); 「 Arrays.asList(strs2)」是 System.out.println()這個方法的入口參數。數組類型的實例,例如Object[] strs2=list.toArray(); 這個strs就是一個數組類型的實例,就是你要用數組類型的實例給與toArrays()給這個方法。
D. python轉換成c#
usingSystem.Security.Cryptography;
publicstringDecrypt(stringpToDecrypt,stringsKey)
{
byte[]inputByteArray=Convert.FromBase64String(pToDecrypt);
using(DESCryptoServiceProviderdes=newDESCryptoServiceProvider())
{
des.Key=ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV=ASCIIEncoding.ASCII.GetBytes(sKey);
System.IO.MemoryStreamms=newSystem.IO.MemoryStream();
using(CryptoStreamcs=newCryptoStream(ms,des.CreateDecryptor(),CryptoStreamMode.Write))
{
cs.Write(inputByteArray,0,inputByteArray.Length);
cs.FlushFinalBlock();
cs.Close();
}
stringstr=Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
returnstr;
}
}
byte[]byData=newbyte[100000];
char[]charData=newchar[1000000];
try
{
FileStreamsFile=newFileStream("config.bin",FileMode.Open);
sFile.Read(byData,0,100);
}
catch(IOExceptione)
{
return;
}
Stringresult=Decruypt(byData.ToString(),"xE3xA5xE3xA5xE3xA5xE3xA5")
E. python 怎麼讀取 Label 裡面的值
#簡單來說 LabelEncoder 是對不連續的數字或者文本進行編號
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
le.fit([1,5,67,100])
le.transform([1,1,100,67,5])
輸出: array([0,0,3,2,1])
#OneHotEncoder 用於將回表示分類的數據答擴維:
from sklearn.preprocessing import OneHotEncoder
ohe = OneHotEncoder()
ohe.fit([[1],[2],[3],[4]])
ohe.transform([2],[3],[1],[4]).toarray()
輸出:[ [0,1,0,0] , [0,0,1,0] , [1,0,0,0] ,[0,0,0,1] ]
F. 關於ArrayList的toArray(T[])方法求解
把一個list對象轉換成String類型的數組。
返回按適當順序(從第一個元素到最後一個元素)包含列表中所有元素的數組;返回數組的運行時類型是指定數組的運行時類型。
也可以這么寫(String[])v.toArray(new String[]{});
G. C# 數組list的問題 如何用toarray
你這是索引問題哈,跟你問的問題兩碼事。你的list長度不足四位。你的代碼最好不要<4,因為你不能保證你的List長度一定會 》=4,你應該判斷<bs_emp.Count
H. 求助高手,C#中將string轉為array的問題
後面那段是用來清除空白內容的,問題是象Arraylist這種東西現在一般都不再用了,前面的定義也沒什麼意義,一般寫法是
publicstaticstring[]StringToArray(stringstr,stringsplitChar)
{
if(str==null)returnnull;
string[]sArray=Regex.Split(str,splitChar,RegexOptions.IgnoreCase);//A點
List<string>newarray=newList<string>();
foreach(stringiteminsArray)if(item!="")newarray.Add(item);
returnnewarray.ToArray();
}
當然,高版本的.net中也可以用lamda寫法
publicstaticstring[]StringToArray(stringstr,stringsplitChar)
{
if(str==null)returnnull;
returnRegex.Split(str,splitChar,RegexOptions.IgnoreCase).Where<string>(i=>i!="").ToArray();
}
I. 關於collection的toArray()方法。
這是一個泛型的典型問題
創建List的時候這樣即可 ArrayList<String> x =new ArrayList<String>();
不考慮繼承關系,可以簡單的解釋為
class ArrayList<T>{
public <T> T[] toArray(T[] a) {
}
}
當你這樣做的時候: ArrayList<String> x =new ArrayList<String>();
T相當於String
當你這樣做的時候: ArrayList x =new ArrayList();
T相當於Object 返回的即Object[] 需要強制類型轉換