- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我快完成这个程序了,但是我无法得到我想要的输出。这是代码:
import numpy as np
filename = (raw_input("Which file are we loading? "))
header = input("How many header lines? ")
# Input variables for column numbers and limiting factors
pcol = input("What column number is parallax in? ")
vcol = input("What column number is Vmag (or other limiting mag) in? ")
pmcol = input("What column number does proper motion begin in (Mu/PA or MuRa MuDec format) ")
ra = input("What column number is RA1 in? (h m s format) ")
dec = input("What column number is Dec1 in? (d m s format) ")
maglim = input("What is your limiting (dimmest) magnitude? ")
parlim = input("What is your limiting (farthest) parallax? ")
# Read in entire file
data = np.loadtxt(filename,skiprows=header,dtype=str)
# Select correct columns
parallax_str = data[:,pcol-1]
ra1_str = data[:,(ra-1)]
ra2_str = data[:,(ra)]
ra3_str = data[:,(ra+1)]
dec1_str = data[:,(dec-1)]
dec2_str = data[:,(dec)]
dec3_str = data[:,(dec+1)]
vmag_str = data[:,vcol-1]
pm1_str = data[:,(pmcol-1)]
pm2_str = data[:,(pmcol)]
# Convert selected strings to floats
parallax = parallax_str.astype(float)
vmag = vmag_str.astype(float)
pm1 = pm1_str.astype(float)
pm2 = pm2_str.astype(float)
criteria = (parallax>=parlim) & (vmag<=maglim)
vmag = vmag[criteria]
parallax = parallax[criteria]
pm1 = pm1[criteria]
pm2 = pm2[criteria]
ra1_str = ra1_str[criteria]
ra2_str = ra2_str[criteria]
ra3_str = ra3_str[criteria]
dec1_str = dec1_str[criteria]
dec2_str = dec2_str[criteria]
dec3_str = dec3_str[criteria]
newlist = np.vstack((ra1_str,ra2_str,ra3_str,dec1_str,dec2_str,dec3_str,vmag,parallax,pm1,pm2))
newlist = newlist.T
np.savetxt('observe.list',newlist,fmt='%s')
现在,这给了我一个看起来像这样的文件:
00 19 05.563 -09 57 53.47 9.92 47.43 -35.62 -301.99
00 24 25.933 -27 01 36.38 7.91 54.87 665.64 83.67
00 39 21.806 +21 15 01.71 5.87 90.42 -461.32 -370.02
00 45 04.894 +01 47 07.88 8.01 46.37 -49.08 -573.23
00 48 22.977 +05 16 50.21 5.72 134.14 757.11 -1141.33
00 51 21.754 +18 44 21.31 9.21 46.79 54.1 -267.14
但是,我想要一个如下所示的文件:
00 19 05.563 -09 57 53.47 9.92 47.43 -35.62 -301.99
00 24 25.933 -27 01 36.38 7.91 54.87 665.64 83.67
00 39 21.806 +21 15 01.71 5.87 90.42 -461.32 -370.02
00 45 04.894 +01 47 07.88 8.01 46.37 -49.08 -573.23
00 48 22.977 +05 16 50.21 5.72 134.14 757.11 -1141.33
00 51 21.754 +18 44 21.31 9.21 46.79 54.10 -267.14
这样一切都是右对齐的。谁能帮我想出一个有效的方法来做到这一点?
干杯。
最佳答案
您可以通过将序列传递给“fmt”关键字参数来为每一列制作不同的格式。以下三个示例显示了不同的选项。更多信息请访问 docs.scipy.org。
>>> import numpy as np
>>> a = np.random.random((3,4))
>>> a[1] = a[1] + 10
>>> a
array([[ 0.66860114, 0.29021582, 0.47168711, 0.86839242],
[ 10.41030497, 10.22771623, 10.80389801, 10.6170771 ],
[ 0.47201727, 0.90861352, 0.03952651, 0.67245859]])
>>>
>>> # saved using string format
>>>
>>> np.savetxt('string.txt', a, fmt='%s')
>>> with open('string.txt','r') as f: print(f.read())
...
0.668601144977 0.290215822112 0.471687110847 0.86839242197
10.4103049716 10.2277162318 10.8038980106 10.617077099
0.472017270547 0.9086135154 0.0395265080276 0.672458588797
>>>
>>> # saved using floating format with the "width" parameter = 10
>>>
>>> np.savetxt('fixed.txt',a, fmt='%10.4f')
>>> with open('fixed.txt','r') as f: print(f.read())
...
0.6686 0.2902 0.4717 0.8684
10.4103 10.2277 10.8039 10.6171
0.4720 0.9086 0.0395 0.6725
>>>
>>> # saved using format specifier sequence with format for each column
>>>
>>> np.savetxt('multi.txt',a, fmt=('%5.2f', '%10.4f', '%7.3f', '%12.1f'))
>>> with open('multi.txt','r') as f: print(f.read())
...
0.67 0.2902 0.472 0.9
10.41 10.2277 10.804 10.6
0.47 0.9086 0.040 0.7
关于python - 特定的列宽和与 savetxt 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34010451/
我希望能够像在 jsFiddle 中那样将元素列表对齐到右侧的复选框。这是如何做到这一点的最佳实践?传统上我从来没有 float 过相互嵌套的元素,所以我想确定这是否是解决此问题的正确方法。 代码(h
指令.align n是什么意思在数组中做什么? 更具体地说,假设我有以下部分代码: array: .align 2 .space 800 它的重要性是什么,为什么不跳过它并使用
基本上我正在寻找一种强制特定相对对齐的方法 即我想保证其他一些值(value) m s.t m > n alignment_of(foo) % 2^m == 2^n IE: .align 2^m; .
在我的代码中,我必须考虑一个数组数组,其中内部数组具有固定维度。为了使用 STL 算法,将数据实际存储为数组的数组很有用,但我还需要将该数据传递给 C 库,该库采用扁平化的 C 样式数组。 如果能够以
横向上,我想显示两个位图,并在它们之间显示一个标签字段。 代码看起来很简单,但所有字段都添加在屏幕左侧。 HorizontalFieldManager hfm = new HorizontalFiel
我想绘制一个变量名称及其符号。因为某些变量的名称很长,所以我试图将换行符与轴标签混合使用。这会导致对齐中发生有趣的事情: par(mar=c(1,12,1,1)) plot( y=1:6, 1:6,
使用这个脚本 df <- data.frame(x = 1:5, y = 1:5, color = letters[1:5]) ggplot(df, aes(x, y, fill = color))
我有一个带有标量字段的结构,比如妈妈,我想在屏幕上对齐的列中显示结构的值,可能还有一些标题。这是一个最小的工作示例: mom.a = 1; mom.b = 2; mom.veryLongName =
在 iOS6 中,我使用自动布局。 我有 2 个以编程方式创建的 View v1 和 v2。 v2 作为 subview 添加到 v1 v1 的约束已通过编程方式创建(此处未显示)。 我希望 v1 和
概述 浏览时operator new, operator new[] - cppreference.com ,似乎我们有许多选项来分配具有特定对齐要求的对象数组。但是,没有指定如何使用它们,而且我似乎
Widget _createProfileContainer() { return new Container( height: 64.0, child: ne
我正在使用 Bootstrap 和语义 UI 的组合来设计和对齐我的网页。目前,我在将页面 api map 和博客文章在整个页面上对齐时遇到问题,而不是像图像所示 那样堆叠在一起。 这是我的底层代码,
所以我已经添加了标签和所有内容,但我仍然在格式化和对齐所有内容时遇到问题。计算按钮显然应该居中。我知道使用 gridbag 将框架分割成坐标系,当一列大于其他列时,它会调整其他列并将其抛弃(对吗?)。
我必须将程序上的按钮对齐到中间,我运行的当前代码但显示的按钮与程序一样大,我想要一个特定大小的中心按钮,这是我尝试过的 /** * Created by Timk9 on 11/04/2016.
我正在尝试将 VIM 作为我的 ruby/rails 编辑器。太胖了,我对它的功能印象深刻 并且我能够安装以下插件以提供更好的 IDE 体验 自动配对 Better-snipmate-snippe
在结构内对齐成员的最佳或常规方法是什么?添加虚拟数组是最佳解决方案吗? 我有一个 double 的结构和 double 的三倍是吗? struct particle{ double mass;
我正在尝试对齐我的输出,但由于某种原因我无法做到我多么想要它,这真的很令人沮丧。标题不会正确对齐。我不知道我是否正确使用了 setw()。 #include using std::cout; usi
我正在开发一个 android 应用程序,其相对布局如下所示。 这是应用程序在屏幕上的显示方式的 imgur 链接:http://imgur.com/c4rNJ .我希望“Text 1”出现在“a l
我不确定为什么我不能在下面的代码中调整按钮的位置。我有几行设置了边界,但我一定遗漏了一些东西。 public DayGUI() { mainFrame = new JF
我有一个 html 页面,我想在页面底部对齐一个 iframe,使 iframe 占据所有宽度,我无法在底部对齐 iframe。请找到底部的 iframe 标签页面。 The rest of th
我是一名优秀的程序员,十分优秀!