Bill Allombert on Sun, 07 Jan 2024 14:26:59 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Two questions about vector and matrix manipulation
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: Two questions about vector and matrix manipulation
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Sun, 7 Jan 2024 14:25:32 +0100
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1704634017; c=relaxed/relaxed; bh=AeDpRXC3nXiZnyAUjbZw7RJZRxXPGLE5xUbgVofC1YY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; b=dfArGrSCksiujpf8BDiNlpIpvEr/oPHyVoAE7fsXQYq5yJfFpLWfmIsJE5EVYQPhD1zxXtt3LHu88LllKghreMHMa9jCf+A1/wAvRzbwYZQaDQ6Wtr0vSPJP5uYwGPeI8QNvgHX1p0tCNoegkZ+OEVTVTyjrBYitDRCK96/H5XnuRJ2DUwt60tfMThM5gjvEIYLvSI5iP35pvycaZmrgvoQ+E9XULmE5y8qOV320KBZqrZCmRmT9l4eW8dXjP/VHvjyaD+nL8J9GHmDqToZCuBE+BCjCOMgXCj86RGif4TlLQcMrGurbG22fUSSarK6d+vzkXkT2YBeRGdzQZILwRsiqk1eubQzZC79bUV7Qo//7uQazjTlJz7m+CWXxEEQxV7jBzbjFIxgG1v7Kejc4BNIWmaPK4tDk6WP3dZyRILfreCJ52FPrOdPfllpe1ZiNTUmMcYES7nRPQ2s4PScM0IcuGQpeqmSeI5eHW4x+rRr3GpV0ubaB1AAWg5XJtuJtw9qMakOnDdDaio76r/KFvI6R4ThEnx/pAZbQj0qM9amNHxD2ilo53/eMy8LEgU5/IYSmTMH2BEQtJ/1BTWpSxrwHWrn4K+71fXcfqRuUrNcGcx68r87oqMzu4GmzYobHRVhi45EZHOSeslxbUzaUThQsFeSE5px6KTCpmQRczgc=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1704634017; cv=none; b=WDWlmrskvTI1LsrRpykBlFr9sug2GX6hCxiurKk+2PGW88UaUytd++QeD330449GDOSF3efCy3jGTDJra9Ua9thOqY97LS8CYGTzPNB8zBIJJnZXB1zlwMPKQ4BwMI4nEA8tci3qaTLYDSjn5yeoUiaQZ6rnEQ9+5JhHWZ7wAAC7o071C74PiACNSiNqomUd0GON+NHQ5OPJ8cecD6zsihS4xeakelCEMVPy2DFz3wwFU9d2zqbKdGzlVfdevX7K8O20FRiiENb507okYOr5P2xrhd5gUvIZB6PfUqL/9b448BZ4ZcnBiJrlSilVnjcQWWeQgfBd6DAiIBYufj5o31hGUJb4r8WCh5iXKIZ54cRUp8on+nNPTwY7KZjCJxYQD59DhNe+ueV2/fbc9Lv7hbvuTKwj0CtJJvLrNlsXRY0JTYvT4sbJCmwjG9ylU6GWbPuNZlUnTatiXLDA2izA+rz+y2/52KJDqxeU83lYw5TQaONL0+O+eIeQDQuyxfSeqFDE7Dfb9IHUUMXIpE1A/fw6Mk0HeBogWmv5hTUGLbVj3v+XegZbztCxzi1dTLRZNS1BBnRTf4KdD5llUuE34ReWIRJ82d4Dn245caf/bazDnOVMUVPfpdDf3HPTz5IKPUSgGxKS+anUTTYUpCStyYIaF74BdtwA2vNuHdXTNTU=
- Authentication-results: smail; arc=none
- Delivery-date: Sun, 07 Jan 2024 14:26:59 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1704634017; bh=AeDpRXC3nXiZnyAUjbZw7RJZRxXPGLE5xUbgVofC1YY=; h=Date:From:To:Subject:References:In-Reply-To:From; b=eP/NoPOO8iUqko0IfwqJ5ZbdOO1m6pdcmbATuXdyv8PuzzndgRicqnAu44gByxTzT ryzcnfxxI7kpByQ2HwU/8xvqiLZ0FY29y9l9qoWxTvdKqzzmgU9dymo09lx7R4p5X2 QRD9iWKJTf7QMr4UioVcDpQx3q7K2sAxm5egOuaBZVuDWnZ/kF8ZXvkELRN7T5Q/Lk un7yyNiZ9erLP9V506t9NStCVYDZwM2YkNCvY80LN8Ucl9ldf+oFYAZCrVcDH4bnHn 5kq1GdQXa3SCWwMUJVsUPb+/0ucoGvtcz0Qmpba/Ol+SnAUu/2SqlwXr+aWFNleocY FAWuQKVqb5VbujpyEyumwgB1of4sJzqym4sR4/1N3eADKKRn8QZhH1shPoe0vqpKxm qkZEw2E/hSJbrjnuEe9SorXQWitdCkEJ6WDxs+ykQzC+3/yKP/YjdFwd1L6nVrI52B u0T2rqgfaP0fidW9PP9p3p9Grnr7fwpExi+hGQeSVXgZ8hPoEsqmGCcEiorEGVsomH xyB8DTa9d8z9hB+3RaU8ca+lcDOP0nBT8X2TNMMNg0DUaRj3/n6vpNWU3l2z30PKcH vp3owf47BCrPRreC5VADsR9KLpPAV0FRxKCeCjyYJZvpP1vdG4TYT0hVa7Dg5Fg4VY ii4GVom6H/l0NBBaea2SivQc=
- In-reply-to: <CAEdMSjens8z3O3kzaEONjKjRNvbiPPXv3Xh6kinAg6H94=k=+A@mail.gmail.com>
- Mail-followup-to: pari-users@pari.math.u-bordeaux.fr
- References: <CAEdMSjens8z3O3kzaEONjKjRNvbiPPXv3Xh6kinAg6H94=k=+A@mail.gmail.com>
On Sun, Jan 07, 2024 at 05:25:22PM +1100, Joe Slater wrote:
> Thanks for the responses to my previous question. I have a couple of
> queries regarding vectors and matrices.
>
> 1) Suppose I want a vector representing the pairwise product of two similar
> vectors. Is there a faster/more elegant way to return this product other
> than explicitly multiplying each element? That is, something better than
> this:
> a=[1,2,3];b=[4,5,6];c=vector(#a,i,a[i]*b[i])
>
> I need the solution to also work if the elements of one vector are also
> vectors:
> a=[[1,2],[3,4]];b=[4,5];c=vector(#a,i,a[i]*b[i])
This is probably the best.
> 2) Suppose I have two vectors of inconsistent length. I want a third vector
> representing their sum, as if the shorter vector had been padded with zeros
> like so:
> f(a,b)=my(k=#a-#b);c=vector(abs(k));if(k>0,b=concat([b,c]),a=concat([a,c]));return(a+b)
> Is there a better/more elegant way to do this?
Well you can use Vec(...,n) to pad with 0.
f(a,b)=a=Vec(a,#b);vector(#a,i,a[i]+b[i])
? f([1,2],[1,2,3])
%5 = [2,4,3]
Cheers,
Bill.