Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
> Loop over Reducing Matrix Dimensionality
Valjean
post Feb 29 2016, 05:57 PM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 15
Joined: 22-February 16
Member No.: 19,047



My goal is to take a set of vectors, which run over an index i, and reduce their dimensionality by one for every zero in the array. In particular, I have a set of vectors which have elements

vecA_$i=[ a 0 0 0 0 0 0 0 0 0 0 0 0 0 0 b ]

and I just want to reindex them to have the vector [ a b ]. If I have just one vector, I can do

VecA_1=("${VecA_1[@]:0}")

and this works just fine. However, I am having difficulty doing this over a loop. I attempted to do

for (( i=1; i<=$directory; i++ ))
do
VecA_$i=("${VecA_$i[@]:0}")
done

but this results in a syntax error on the definition line. Can anyone advise how to perform a do loop over a matrix dimensionality reduction?
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
michaelk
post Mar 1 2016, 12:50 PM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Support Specialist
Posts: 1,800
Joined: 23-January 03
Member No.: 360



You have to use indirect like before:
CODE
i=1
test_1=(a 1 2 3 4 5 6 b)
echo "before" ${test_1[@]}
dtest=temp_$i
eval test_${i}="${!dtest[@]:2}"
echo "after" ${test_1[@]}


The string command ${string:0] extracts the entire string so basically nothing happens. The basic command extracts the substring starting at position x. In my code x=2 so the array would then be:
(1 2 3 4 5 6 cool.gif. I don't know if it will work but you can try to use use regular expressions (expr) to extract all zeros.

www.tldp.org/LDP/abs/html/string-manipulation.html
Go to the top of the page
 
+Quote Post
Valjean
post Mar 2 2016, 12:59 AM
Post #3


Whats this Lie-nix Thing?
*

Group: Members
Posts: 15
Joined: 22-February 16
Member No.: 19,047



QUOTE (michaelk @ Mar 1 2016, 12:50 PM) *
You have to use indirect like before:
CODE
i=1
test_1=(a 1 2 3 4 5 6 b)
echo "before" ${test_1[@]}
dtest=temp_$i
eval test_${i}="${!dtest[@]:2}"
echo "after" ${test_1[@]}


The string command ${string:0] extracts the entire string so basically nothing happens. The basic command extracts the substring starting at position x. In my code x=2 so the array would then be:
(1 2 3 4 5 6 cool.gif. I don't know if it will work but you can try to use use regular expressions (expr) to extract all zeros.

www.tldp.org/LDP/abs/html/string-manipulation.html


Thank you!
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 15th December 2017 - 01:00 PM