On 10/19/2010 09:41 PM, 李季 wrote: > Thanks! > But it does't work well. > > import numpy as np > a = np.array([[1.1, 2, 3], [4, 5, 6]]) > a.astype(int) > b = a[0,0] / a[1,0] > print b > print a > > the result is as follow: > > 0.275 > [[ 1.1 2. 3. ] > [ 4. 5. 6. ]]
According to http://www.scipy.org/Numpy_Example_List_With_Doc#head-0b5453f877a02c72c8bb3196ce2e37af83c9eff7 astype returns a cast copy of the array, so you could do a = a.astype(int) or work with a2 = a.astype(int) Does this help? > I use the notebook. > > 2010/10/20 Nils Bruin <nbr...@sfu.ca <mailto:nbr...@sfu.ca>> > > On Oct 19, 6:57 pm, 李季 <liji.ma...@gmail.com > <mailto:liji.ma...@gmail.com>> wrote: > > Dear group, > > I have a question as follow: > > > > import numpy as np > > > > B = np.array([[1, 2, 3], [4, 5, 6]]) > > > > Is there any command that I can use to convert B to a float-type? > > For more information you should probably look at the numpy manual and/ > or numpy mailing lists and newsgroups. The direct answer to your > question: > > B.astype(float) > > -- > To post to this group, send email to sage-support@googlegroups.com > <mailto:sage-support@googlegroups.com> > To unsubscribe from this group, send email to > sage-support+unsubscr...@googlegroups.com > <mailto:sage-support%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/sage-support > URL: http://www.sagemath.org > > > -- > To post to this group, send email to sage-support@googlegroups.com > To unsubscribe from this group, send email to > sage-support+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-support > URL: http://www.sagemath.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org