-1

ネストされた 2 つのベクトル x と y が与えられます。ここで、x は

 (def x [[1 2] [3 4]])

そしてyは

 (def y [[5 6] [7 8]])

ネストされたベクトル x と y を、追加の入力 d で指定された次元の配列に沿って連結するにはどうすればよいですか?

つまり、x、y、d=1 の場合、サンプル出力は次のようになります。

[[1 2] [3 4] [5 6] [7 8]]

ここで、y は新しいネストされたベクトルの 3 番目と 4 番目の行になります。

d=1 の場合、私は試しました

(vec (concat [[1 2] [3 4]] [[5 6] [7 8]].

初期の x と ya で d=2 の場合、サンプル出力は次のようになります。

[[1 2 5 6] [3 4 7 8]]

これは私が最も確信が持てない場合です。

d=3 の場合、x と y は 2 x 2 なのでそのまま残されます。したがって、x と y はそのまま出力されます。

4

1 に答える 1

1

core.matrixライブラリは、任意の次元に沿って行列をスライスするのに優れています。

project.clj:

(defproject hello "0.1.0-SNAPSHOT"                                 
  :description "FIXME: write description"                          
  :url "http://example.com/FIXME"                                  
  :license {:name "Eclipse Public License"                         
            :url "http://www.eclipse.org/legal/epl-v10.html"}      
  :dependencies [[org.clojure/clojure "1.5.1"]                     
                 [net.mikera/core.matrix "0.18.0"]]                
  :source-paths ["dev"])                                           

こんにちは/matric.clj:

(ns hello.matrix                                        
  (:refer-clojure :exclude [* - + == /])                
  (:use [clojure.core.matrix]                           
        [clojure.core.matrix.operators]                 
        [clojure.pprint]))                              

(def x (matrix [[1 2] [3 4]]))                          
(def y (matrix [[5 6] [7 8]]))                          
(def xy (matrix [x y]))                                 

(pprint (slices xy 0))                                  
(pprint (slices xy 1))                                  
(pprint (slices xy 2))  
于 2013-12-26T20:27:17.870 に答える