[sage-support] Array

2015-02-26 Thread Santanu Sarkar
Dear all,

  How to define 3D array like in C language
double A[10][10][10];

For 1D array I use  A=[0]*10 and for 2D array
I use matrix A=matrix(RR,10,10, range(10*10)) in Sage


Best,
Santanu

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Array in Sage

2013-05-19 Thread Santanu Sarkar
Is the any way to write four dimensional array in Sage like C
int M[10][10][10][10]?  For two dimensional case I use Matrix.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sage-support] Array of Arrays

2012-10-01 Thread Justin C. Walker

On Oct 1, 2012, at 00:28 , Santanu Sarkar wrote:

> I have written the following:
> 
> T=[0]*2
> S=[]
> l=2
> for i in range(l):
>T[0]=i
>T[1]=i+1
>print T
>S.append(T)
> 
> Now S becomes [[1, 2], [1, 2]] instead of [[0,1],[1,2]].
> In my situation, length l of S is not fixed. Is there any
> method to solve this problem?

This is the result of a feature of the Python language.  'T' is the name of an 
array, and acts like its address, so as you append T to S, you are continually 
reusing that same address.  When you update the elements in T (by, e.g., 
"T[0]=i"), you are modifying the content of T.

To avoid this, you could do something like

S=[]
l=2
for i in range(l):
print T
S.append([i,i+1])

For details, check the python documentation, in particular, the difference 
between copy() and deepcopy().

Maybe start here:
  

HTH

Justin

--
Justin C. Walker, Curmudgeon at Large
Director
Institute for the Enhancement of the Director's income
---
--
They said it couldn't be done, but sometimes,
it doesn't work out that way.
  - Casey Stengel
--



-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
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.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




[sage-support] Array of Arrays

2012-10-01 Thread Santanu Sarkar
I have written the following:

T=[0]*2
S=[]
l=2
for i in range(l):
T[0]=i
T[1]=i+1
print T
S.append(T)

Now S becomes [[1, 2], [1, 2]] instead of [[0,1],[1,2]].
In my situation, length l of S is not fixed. Is there any
method to solve this problem?

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
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.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




Re: [sage-support] Array and Loop in Sagetex

2012-05-07 Thread arshpreet singh
> It just tell how to apply forloop.
ok . i am waiting for my sage-code to be compiled.it is taking t
long :) after that we solve

-- 
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


Re: [sage-support] Array and Loop in Sagetex

2012-05-07 Thread Priyanka Kapoor
>> How to pass value of list in sageblock to variable used in \forloop
> may be it can help http://mathematics.nsetzer.com/latex/latex_for_loop.html

It just tell how to apply forloop.



-- 
Priyanka Kapoor
http://kapoorpriyanka.in
Linux User Group, Ludhiana

-- 
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


Re: [sage-support] Array and Loop in Sagetex

2012-05-07 Thread arshpreet singh
On Mon, May 7, 2012 at 3:12 PM, Priyanka Kapoor
 wrote:
>> It looks like you want TeX to do the loop. Try the forloop package:
>> http://www.ctan.org/tex-archive/macros/latex/contrib/forloop/
>>
>
> How to pass value of list in sageblock to variable used in \forloop
may be it can help http://mathematics.nsetzer.com/latex/latex_for_loop.html

-- 
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


Re: [sage-support] Array and Loop in Sagetex

2012-05-07 Thread Priyanka Kapoor
> It looks like you want TeX to do the loop. Try the forloop package:
> http://www.ctan.org/tex-archive/macros/latex/contrib/forloop/
>

How to pass value of list in sageblock to variable used in \forloop




-- 
Priyanka Kapoor
http://kapoorpriyanka.in
Linux User Group, Ludhiana

-- 
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


Re: [sage-support] Array and Loop in Sagetex

2012-05-03 Thread Dan Drake
On Thu, 03 May 2012 at 04:58PM +0530, Priyanka Kapoor wrote:
>  \begin{sageblock}
> v= [x^2, sin(x)]
>  \end{sageblock}
> 
>  Here's a plot of $f$ from $-2$ to $2$:
> for i in range(2):
> \sageplot[width=10cm]{plot(v[i],(x,
> -2,2),legend_label='sin(x)',aspect_ratio =1)}
>  \end{document}

You are putting Python code into your TeX document, but TeX will typeset
it, not ask Python/Sage to process it.

It looks like you want TeX to do the loop. Try the forloop package:
http://www.ctan.org/tex-archive/macros/latex/contrib/forloop/

Dan

--
---  Dan Drake
-  http://mathsci.kaist.ac.kr/~drake
---


signature.asc
Description: Digital signature


[sage-support] Array and Loop in Sagetex

2012-05-03 Thread Priyanka Kapoor
I tried this plot using sage with Latex.
\documentclass{article}
\title{Curve Tracing by SAGE in \LaTeX}
 \author{Priyanka Kapoor}
\usepackage{sagetex}
\begin{document}
\maketitle
Plot the curve for sin(X)
\begin{sageblock}
 f(x) = sin(x)
\end{sageblock}
Here's a plot of $f$ from $-2$ to $2$:

\sageplot[width=10cm]{plot(f,(x, -2, 2),legend_label='sin(x)',aspect_ratio =1)}
\end{document}

How to use Array and Loop in this program around \sageplot portion.
I tried this:

 \begin{sageblock}
v= [x^2, sin(x)]
 \end{sageblock}

 Here's a plot of $f$ from $-2$ to $2$:
for i in range(2):
\sageplot[width=10cm]{plot(v[i],(x,
-2,2),legend_label='sin(x)',aspect_ratio =1)}
 \end{document}

It doesn't work :-( Where to apply loop then. In sageblock or in latex body?
please help.




-- 
Priyanka Kapoor
http://kapoorpriyanka.in
Linux User Group, Ludhiana

-- 
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


Re: [sage-support] Array

2010-10-10 Thread Mike Hansen
On Sun, Oct 10, 2010 at 7:26 AM, Santanu Sarkar
 wrote:
> How one can define an array of length 1?
> For example an array of length 4 is X = [1, 2, 1, 3].

In that example, you are actually defining a Python *list* rather than
an array.  If you want to create a list of length 1, one way to do
it would be to do:

X = [None]*1

Every entry in that list will be the Python object None.

--Mike

-- 
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


[sage-support] Array

2010-10-10 Thread Santanu Sarkar
How one can define an array of length 1?
For example an array of length 4 is X = [1, 2, 1, 3].

-- 
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


Re: [sage-support] array with "Field of Arbitrary Precision Real Numbers"

2010-01-07 Thread Robert Bradshaw

On Dec 21, 2009, at 6:31 AM, Mike Hansen wrote:


Hello,

On Mon, Dec 21, 2009 at 5:34 AM, daan  wrote:

For simulations I'm running, I'd like to perform some calculations
with an arbitrary precision, but I want to store my variables in
arrays so I can iterate through them for calculations. I've found
http://www.sagemath.org/doc/reference/sage/rings/real_mpfr.html for
working with real numbers with arbitrary precision, but I can't  
figure

out if/how I can put those numbers in arrays.


Sage has arbitrary fixed precision floating point arithmetic.   You
can make a matrix with these as entries like this:


You can also use Python lists, if all you need to do is index and  
iterate over them.


http://diveintopython.org/native_data_types/lists.html


sage: m = matrix(RealField(1000), 2, 2, [[1,2],[3,4]])

All of the entries will be real numbers with 1000 bits of precision.
Let us know if there are any other questions you have.


It should be noted that matrix operations in this case are done using  
the naive algorithms, with no regard for numerical stability. (We'd  
love for someone who knows about this area to fix that.) Matrices over  
RDF and CDF (53 bits only) do use more appropriate algorithms from  
SciPy and NumPy.


- Robert

-- 
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


Re: [sage-support] array with "Field of Arbitrary Precision Real Numbers"

2009-12-21 Thread Mike Hansen
Hello,

On Mon, Dec 21, 2009 at 5:34 AM, daan  wrote:
> For simulations I'm running, I'd like to perform some calculations
> with an arbitrary precision, but I want to store my variables in
> arrays so I can iterate through them for calculations. I've found
> http://www.sagemath.org/doc/reference/sage/rings/real_mpfr.html for
> working with real numbers with arbitrary precision, but I can't figure
> out if/how I can put those numbers in arrays.

Sage has arbitrary fixed precision floating point arithmetic.   You
can make a matrix with these as entries like this:

sage: m = matrix(RealField(1000), 2, 2, [[1,2],[3,4]])

All of the entries will be real numbers with 1000 bits of precision.
Let us know if there are any other questions you have.

--Mike

-- 
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


[sage-support] array with "Field of Arbitrary Precision Real Numbers"

2009-12-21 Thread daan
Hi all,

For simulations I'm running, I'd like to perform some calculations
with an arbitrary precision, but I want to store my variables in
arrays so I can iterate through them for calculations. I've found
http://www.sagemath.org/doc/reference/sage/rings/real_mpfr.html for
working with real numbers with arbitrary precision, but I can't figure
out if/how I can put those numbers in arrays.
Another option would be to have arrays of pointers, pointing to
variables defined as above, but again I have no idea if and how this
is possible.

Can anybody point me in the right direction for this?

Thanks!
Daan

-- 
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


[sage-support] array cannot be safely cast to required type

2009-04-09 Thread Flavio Coelho

Hi I having trouble with running code within sage which runs perfectly
in straight Python:

import scipy.stats as stats
import numpy

def lhsFromSample(sample,siz=100):
"""
Latin Hypercube Sample from a set of values

:Parameters:
- `sample`: list, tuple of array
- `siz`: Number or shape tuple for the output sample
"""
if not isinstance(sample, (list,tuple,numpy.ndarray)):
raise TypeError('sample is not a list, tuple or numpy vector')
n = siz
if isinstance(siz,(tuple,list)):
n=numpy.product(siz)
perc = numpy.arange(0,100.,100./n)
numpy.random.shuffle(perc)
smp = [stats.uniform(i,100./n).rvs() for i in perc]
v = numpy.array([stats.scoreatpercentile(sample,p) for p in smp])
if isinstance(siz,(tuple,list)):
v.shape = siz
return v

def lhsFromDensity(kde,siz=100):
'''
LHS sampling from a variables Kernel density estimate.

:Parameters:
- `kde`: scipy.stats.kde.gaussian_kde object
- `siz`: Number or shape tuple for the output sample
'''
if not isinstance(kde,scipy.stats.kde.gaussian_kde):
raise TypeError("kde is not a density object")
if isinstance(siz,(tuple,list)):
n=numpy.product(siz)
s = kde.resample(n)
v = lhsFromSample(s,n)
if isinstance(siz,(tuple,list)):
v.shape = siz
return v


def lhs(dist, parms, siz=100):
'''
Latin Hypercube sampling of any distrbution.
dist is is a scipy.stats random number generator
such as stats.norm, stats.beta, etc
parms is a tuple with the parameters needed for
the specified distribution.

:Parameters:
- `dist`: random number generator from scipy.stats module.
- `parms`: tuple of parameters as required for dist.
- `siz` :number or shape tuple for the output sample
'''
if not isinstance(dist, (stats.rv_discrete,stats.rv_continuous)):
raise TypeError('dist is not a scipy.stats distribution
object')
n=siz
if isinstance(siz,(tuple,list)):
n=numpy.product(siz)

perc = numpy.arange(0,1.,1./n)
numpy.random.shuffle(perc)
smp = [stats.uniform(i,1./n).rvs() for i in perc]
v = dist(*parms).ppf(smp)

if isinstance(siz,(tuple,list)):
v.shape = siz
return v

lhs(stats.uniform,(1,30),10)


If I run this code in Sage 3.4 it gives the following error and
traceback:



Traceback (click to the left for traceback)
...
TypeError: array cannot be safely cast to required type

Traceback (most recent call last):
  File "", line 1, in 
  File "/home/fccoelho/.sage/sage_notebook/worksheets/admin/2/code/
4.py", line 79, in 
lhs(stats.uniform,
(_sage_const_1 ,_sage_const_30 ),_sage_const_10 )
  File "/home/fccoelho/Downloads/sage-3.4-linux-Ubuntu_8.10-i686-Linux/
local/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/", line
1, in 

  File "/home/fccoelho/.sage/sage_notebook/worksheets/admin/2/code/
4.py", line 73, in lhs
v = dist(*parms).ppf(smp)
  File "/home/fccoelho/Downloads/sage-3.4-linux-Ubuntu_8.10-i686-Linux/
local/lib/python2.5/site-packages/scipy/stats/distributions.py", line
112, in ppf
return self.dist.ppf(q,*self.args,**self.kwds)
  File "/home/fccoelho/Downloads/sage-3.4-linux-Ubuntu_8.10-i686-Linux/
local/lib/python2.5/site-packages/scipy/stats/distributions.py", line
563, in ppf
place(output,cond,self._ppf(*goodargs)*scale + loc)
  File "/home/fccoelho/Downloads/sage-3.4-linux-Ubuntu_8.10-i686-Linux/
local/lib/python2.5/site-packages/numpy/lib/function_base.py", line
1357, in place
return _insert(arr, mask, vals)
TypeError: array cannot be safely cast to required type


can anyone tell me if this is a Sage "bug" or "feature" ;-)

Flávio

--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---