我已使用datasample()
和randsample()
选择具体的编号。向量随机排列的项目。但我必须指定否。明确显示项目。有什么方法可以指定百分比?
答案 0 :(得分:2)
您可以轻松地在所需数据的百分比和要使用的功能所需的 number 之间进行转换...
student@student:~/Downloads/json/csv$ head < popp.csv
WKT,cat,F_CODEDESC,F_CODE,TYPE
"POINT (-1049809.14913148 6635460.69190277)",1.000,Building,AL015,CABIN
"POINT (441308.810636207 6573953.19546494)",2.000,Building,AL015,CABINS
"POINT (340199.412944192 6540038.90039579)",3.000,Building,AL015,CABIN
"POINT (191579.478604275 6529955.3502767)",4.000,Building,AL015,CABIN
其中fileprivate func setupName(){
let height = CGFloat(50)
lblName.text = "Hello world"
lblName.backgroundColor = .lightGray
//Step 1
lblName.translatesAutoresizingMaskIntoConstraints = false
//Step 2
self.view.addSubview(lblName)
//Step 3
NSLayoutConstraint.activate([
lblName.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor),
lblName.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor),
lblName.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor,constant: -height),
lblName.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor),
])
}
是必须指定的项目数,n = floor( pct * N );
是要输入的百分比(0到1之间),n
是元素总数在向量中。
您可以对pct
(N
/ floor
)使用不同的舍入函数,但是ceil
是一个不错的选择,因此可以防止请求{{ 1}}元素由于数字错误或其他原因。