Dear Emmanuel,

Thank you very much for your explanations... What I should have said after reading you is "converting"

arange() does a sort of x,-2,2 for example (but I am not sure what it does that why I don't want to use something I don't understand. it's like np.linspace() I wonder if it doesn't come from matlab a kind of conversion ?

I think an academic person wouldn't bother about this and would use numpy or scipy, which I don't want to use as it is already in sage too, but transparent.

from __future__ import division,print_function, absolute_import
import struct,warnings,librosa
import numpy as np
from IPython.display import Audio
def wavPlayer(data, rate):
    display(Audio(data, rate=rate))
from matplotlib import pyplot as plt
from scipy.io import wavfile
sr = 22050 # sample rate
T = 2.0    # seconds
t = np.linspace(0, T, int(T*sr), endpoint=False)
x = 0.5*np.sin(2*np.pi*440*t)
librosa.output.write_wav('la440.wav', x, sr)
samplerate,data=wavfile.read("la440.wav")
times=np.arange(len(data))/float(samplerate)
plt.plot(data[:1000]);
Audio(x, rate=sr)

This example shows my interrogation : I need a lot of import to do it... For this program I needed about 2 days looking in google how to find the functions. I don't complaint because people are nicely explaining me what I finished to notice... That's the wonder of mailing list of sage, one never feels lost or not long time.

Regards

Henri


Le 09/01/2018 à 19:53, Emmanuel Charpentier a écrit :
Dear Henri,

When you do
import numpy as np
you are just creating a identifier that allows you to reach for a numpy function that happens to have the same name as another Sage|Python function. You do nor "import" physically anything.
So when you do :
foo=<whatever>
sqrt(foo)
you are in fact calling the Sage functionsqrt, with the argument<whatever> ; that may or may not make sense to Sage.
But if you do
foo=np.<something>()
np.sqrt(foo)
you are calling the Numpy function sqrt, with an argument which is (probably) a Numpy object. np.sqrt(foo) may make sense (as opposed to, say, np.sqrt(bar), where bar is something without relation to Numpy...).

Le mardi 9 janvier 2018 14:33:53 UTC+1, HG a écrit :

    Nothing goes wrong : My question is sage has already lot of functions
    which don't need numpy, but if there is one function which needs
    numpy I
    will have to add it.


Indeed. And you should note that this Numpy function may return something that is a Numpy object, that other Sage functions may or may not be able to use. You may have to convert it back to Sage.

A better example is given by Sympy. You may want to use, for example, its Laplace transform (and inverse thereof), which seem somewhat more capable than the native (Maxima's) one, or its Fourier transforms (which do not even exist in Maxima...).

import sympy
f=<some function of t>
var("s,t")
st,ss=sympy.symbols("st,ss")
F=sympy.fourier__transform(sympy.sympify(f),ss,st)
G=<somethingInterestingInvolvingF>
g=sympy.inverse_fourier_transform(G,st,ss)

At this point, g is something composed of sympy objects (IIRC, a tuup,e, whose first element is the sought inverse Fourier transform). In order to use it in Sage, you have to transform it back (using the ._sage_() method) and possibly rename some variables.

This mechanism has been automated for some operations : for example, that's (very roughly !) what the 'algorithm="sympy"' option of integrate() does.

    And arange needs np then I am asking if there a way
    to do it in sage without using numpy,


So in fact, you are looking for a "pure Sage" implementation of arange(). I do not know what does arange : it migh be trivial it might verge on the impossible, I do not know.

But the point is that mechanisms (which is relatively cheap) offers you a lot of power and flexibility : you can use the arange algorithm even if iot's not implemented|implementable in Sage...

Furthermore, you should consider if you need you result as a Sage object. For your purposes, in may be that (a part of) your algorithm is easier to express with Numpy ; so may be interested by implementing this part with Numpy and convert back to Sage only what you want in Sage...

--
Emmanuel Charpentier

    I am not an expert in sage and I
    try to keep to pure command, I don't like to import lot of libs as
    they
    are already declare in sage, I think is redondant... Then I just
    wanted
    to know if there a way of doing np.arange but only with sage (not
    importing numpy), for example matplolib uses lot of declaration like
    plt... when i do a plot I only use plot(), I prefer look to sage plot
    commands (even if they are from matplotlib) that's why I appreciate
    sage, for latex it's very easy to have it straight because the
    libs are
    in sage.  I use sage to do lot of work maths graphs draw music ...
    etc,
    then I just add them with sage -pip and after I have nothing to
    remenber
    for me sage is a kind of wisiwigsage all-in-one. I am a user not a
    developer (pity for me... I would like to know this better), sage
    is the
    best tool for math in my way. Easy, well documented and much
    more... I
    do a lot of things (maybe not academic) but suiting to my needs... At
    the moment I am in antic chinese music and this requires geometry /
    music / math... sage do all :)

    Regards

    Henri



    Le 09/01/2018 à 13:34, Simon King a écrit :
    > Hi,
    >
    > On 2018-01-09, Girard Henri <henri....@gmail.com <javascript:>>
    wrote:
    >> Am 09.01.2018 um 12:18 schrieb Girard Henri:
    >>> An exemple
    >>>
    >>> from matplotlib import pyplot as plt
    >>> from scipy.io <http://scipy.io> import wavfile
    >>> import numpy as np
    >>> samplerate,data=wavfile.read("test.wav")
    >>> times=np.arange(len(data))/float(samplerate)
    >>> plt.plot(data[:1000])
    > What exactly goes wrong if you do the above in Sage? Please be more
    > specific.
    >
    > In another message to me, you wrote:
    >> Most of the time I don't want to make heavier "import"... First
    because
    >> I don't master it and it's much better to do sqrt() instead
    np.sqrt() or
    >> np.pi()
    > I don't see why sqrt() is better than np.sqrt().
    >
    > Anyway, as usual in Python, you can import functions like this:
    >    sage: from numpy import sqrt
    >    sage: sqrt
    >    <ufunc 'sqrt'>
    >    sage: sqrt(4)
    >    2.0
    >    sage: type(_)
    >    <type 'numpy.float64'>
    >
    > The disadvantage is that it overwrites Sage's sqrt() function.
    That's why
    > I believe it is better to do np.sqrt().
    >
    > Best regards,
    > Simon
    >

--
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 <mailto:sage-support+unsubscr...@googlegroups.com>. To post to this group, send email to sage-support@googlegroups.com <mailto:sage-support@googlegroups.com>.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

--
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 https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to