小编Nav*_*aro的帖子

x, y 数据的逆时针排序

我在文本文件中有一组点:random_shape.dat. 文件中点的初始顺序是随机的。我想按如下逆时针顺序对这些点进行排序(红点是 xy 数据): 在此处输入图片说明

我试图通过使用极坐标来实现这一点:我计算每个点的极角,(x,y)然后按升角排序,如下所示:

"""
Script: format_file.py
Description: This script will format the xy data file accordingly to be used with a program expecting CCW order of data points, By soting the points in Counterclockwise order
Example: python format_file.py random_shape.dat
"""

import sys
import numpy as np

# Read the file name
filename = sys.argv[1]

# Get the header name from the first line of the file (without the newline character)
with open(filename, 'r') as …
Run Code Online (Sandbox Code Playgroud)

python sorting numpy

5
推荐指数
2
解决办法
3170
查看次数

如何解释这种 NumPy 索引:a[2::2, ::2]?

谁能告诉如何解释这种寻址方式:a[2::2, ::2]?我不知道如何使用这种索引。

a = np.random.random((6,6))
print(a)
[[0.17948771 0.61436323 0.48768101 0.20540278 0.15331527 0.17766787]
 [0.40028608 0.63915391 0.92719741 0.56604286 0.92959065 0.92707981]
 [0.27554561 0.09253335 0.73841082 0.00840638 0.33683454 0.89065058]
 [0.25030938 0.37093169 0.70789081 0.95205777 0.60483874 0.81425781]
 [0.14250593 0.56916738 0.45440191 0.21140548 0.72945015 0.59313599]
 [0.68116512 0.45349473 0.23057609 0.36349226 0.622701   0.07951557]]

a[2::2, ::2]
array([[0.27554561, 0.73841082, 0.33683454],
       [0.14250593, 0.45440191, 0.72945015]])
Run Code Online (Sandbox Code Playgroud)

python numpy numpy-slicing numpy-ndarray

1
推荐指数
1
解决办法
50
查看次数

标签 统计

numpy ×2

python ×2

numpy-ndarray ×1

numpy-slicing ×1

sorting ×1