or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

array-operations.mdcuda-integration.mdcustom-kernels.mdfft.mdindex.mdio-operations.mdjit-compilation.mdlinear-algebra.mdmathematical-functions.mdperformance-profiling.mdpolynomial-operations.mdrandom.mdscipy-extensions.md

array-operations.mddocs/

0

# Array Operations

1

2

CuPy provides comprehensive array operations for GPU-accelerated computation, offering NumPy-compatible array creation, manipulation, indexing, reshaping, joining, and splitting operations optimized for CUDA and ROCm platforms.

3

4

## Capabilities

5

6

### Array Creation

7

8

Core array creation functions for initializing GPU arrays with various patterns and data sources.

9

10

```python { .api }

11

def array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0):

12

"""

13

Create an array from an array-like object.

14

15

Parameters:

16

object: array_like - Input data in any form convertible to an array

17

dtype: data-type, optional - Desired data type for the array

18

copy: bool, optional - If True, create a copy of the object

19

order: {'K', 'A', 'C', 'F'}, optional - Memory layout

20

subok: bool, optional - If True, sub-classes will be passed through

21

ndmin: int, optional - Minimum number of dimensions

22

"""

23

24

def zeros(shape, dtype=float, order='C'):

25

"""

26

Return a new array of given shape and type, filled with zeros.

27

28

Parameters:

29

shape: int or tuple of ints - Shape of the new array

30

dtype: data-type, optional - Desired data type for the array

31

order: {'C', 'F'}, optional - Row-major (C) or column-major (F) order

32

"""

33

34

def ones(shape, dtype=None, order='C'):

35

"""

36

Return a new array of given shape and type, filled with ones.

37

38

Parameters:

39

shape: int or tuple of ints - Shape of the new array

40

dtype: data-type, optional - Desired data type for the array

41

order: {'C', 'F'}, optional - Row-major (C) or column-major (F) order

42

"""

43

44

def empty(shape, dtype=float, order='C'):

45

"""

46

Return a new array of given shape and type, without initializing entries.

47

48

Parameters:

49

shape: int or tuple of ints - Shape of the new array

50

dtype: data-type, optional - Desired data type for the array

51

order: {'C', 'F'}, optional - Row-major (C) or column-major (F) order

52

"""

53

54

def full(shape, fill_value, dtype=None, order='C'):

55

"""

56

Return a new array of given shape and type, filled with fill_value.

57

58

Parameters:

59

shape: int or tuple of ints - Shape of the new array

60

fill_value: scalar - Fill value

61

dtype: data-type, optional - Desired data type for the array

62

order: {'C', 'F'}, optional - Row-major (C) or column-major (F) order

63

"""

64

65

def eye(N, M=None, k=0, dtype=float, order='C'):

66

"""

67

Return a 2-D array with ones on the diagonal and zeros elsewhere.

68

69

Parameters:

70

N: int - Number of rows in the output

71

M: int, optional - Number of columns in the output (defaults to N)

72

k: int, optional - Index of the diagonal

73

dtype: data-type, optional - Data type of the returned array

74

order: {'C', 'F'}, optional - Row-major (C) or column-major (F) order

75

"""

76

77

def identity(n, dtype=None):

78

"""

79

Return the identity array.

80

81

Parameters:

82

n: int - Number of rows (and columns) in n x n output

83

dtype: data-type, optional - Data type of the output

84

"""

85

```

86

87

### Array Creation from Data

88

89

Functions for creating arrays from existing data sources including arrays, files, and iterables.

90

91

```python { .api }

92

def asarray(a, dtype=None, order=None):

93

"""

94

Convert the input to an array.

95

96

Parameters:

97

a: array_like - Input data in any form convertible to an array

98

dtype: data-type, optional - Data type

99

order: {'C', 'F'}, optional - Memory layout order

100

"""

101

102

def asanyarray(a, dtype=None, order=None):

103

"""

104

Convert the input to an array, preserving array subclasses.

105

106

Parameters:

107

a: array_like - Input data

108

dtype: data-type, optional - Data type

109

order: {'C', 'F'}, optional - Memory layout order

110

"""

111

112

def ascontiguousarray(a, dtype=None):

113

"""

114

Return a contiguous array in memory (C order).

115

116

Parameters:

117

a: array_like - Input array

118

dtype: data-type, optional - Data type

119

"""

120

121

def copy(a, order='K'):

122

"""

123

Return an array copy of the given object.

124

125

Parameters:

126

a: array_like - Input data

127

order: {'C', 'F', 'A', 'K'}, optional - Memory layout order

128

"""

129

130

def fromfile(file, dtype=float, count=-1, sep=''):

131

"""

132

Construct an array from data in a text or binary file.

133

134

Parameters:

135

file: file or str - Open file object or filename

136

dtype: data-type - Data type of the returned array

137

count: int - Number of items to read (-1 means all data)

138

sep: str - Separator between items for text files

139

"""

140

141

def fromfunction(function, shape, **kwargs):

142

"""

143

Construct an array by executing a function over each coordinate.

144

145

Parameters:

146

function: callable - Function is called with N parameters

147

shape: tuple of ints - Shape of the output array

148

**kwargs: keyword arguments passed to function

149

"""

150

151

def fromiter(iterable, dtype, count=-1):

152

"""

153

Create a new 1-dimensional array from an iterable object.

154

155

Parameters:

156

iterable: iterable object - An iterable object providing data for the array

157

dtype: data-type - The data type of the returned array

158

count: int, optional - The number of items to read from iterable

159

"""

160

161

def frombuffer(buffer, dtype=float, count=-1, offset=0):

162

"""

163

Interpret a buffer as a 1-dimensional array.

164

165

Parameters:

166

buffer: buffer_like - An object that exposes the buffer interface

167

dtype: data-type, optional - Data type of the returned array

168

count: int, optional - Number of items to read

169

offset: int, optional - Start reading buffer from this offset

170

"""

171

172

def fromstring(string, dtype=float, count=-1, sep=''):

173

"""

174

A new 1-D array initialized from text data in a string.

175

176

Parameters:

177

string: str - A string containing the data

178

dtype: data-type, optional - The data type of the array

179

count: int, optional - Read this number of dtype elements from the data

180

sep: str, optional - The string separating numbers in the data

181

"""

182

183

def loadtxt(fname, dtype=float, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0, encoding='bytes', max_rows=None):

184

"""

185

Load data from a text file.

186

187

Parameters:

188

fname: file, str, pathlib.Path, list of str, generator - File to read

189

dtype: data-type, optional - Data type of the resulting array

190

comments: str or sequence of str, optional - Characters or list of characters used to indicate the start of a comment

191

delimiter: str, optional - String used to separate values

192

converters: dict, optional - Dictionary mapping column number to function that converts the column string to the appropriate Python type

193

skiprows: int, optional - Skip the first skiprows lines, including comments

194

usecols: int or sequence, optional - Which columns to read

195

unpack: bool, optional - If True, return data in separate arrays

196

ndmin: int, optional - Minimum number of dimensions that the returned array should have

197

encoding: str, optional - Encoding used to decode the inputfile

198

max_rows: int, optional - Read max_rows lines of content after skiprows lines

199

"""

200

201

def genfromtxt(fname, dtype=float, comments='#', delimiter=None, skip_header=0, skip_footer=0, converters=None, missing_values=None, filling_values=None, usecols=None, names=None, excludelist=None, deletechars=''.join(sorted(NameValidator.defaultexcludelist)), defaultfmt="f%i", autostrip=False, replace_space='_', case_sensitive=True, unpack=None, invalid_raise=True, max_rows=None, encoding='bytes'):

202

"""

203

Load data from a text file, with missing values handled as specified.

204

205

Parameters:

206

fname: file, str, pathlib.Path, list of str, generator - File to read

207

dtype: dtype, optional - Data type of the resulting array

208

comments: str, optional - Characters used to indicate the start of a comment

209

delimiter: str, int, or sequence, optional - String(s) used to separate values

210

skip_header: int, optional - Number of lines to skip at the beginning of the file

211

skip_footer: int, optional - Number of lines to skip at the end of the file

212

converters: variable or None, optional - Set of functions that convert the data of a column to a value

213

missing_values: variable or None, optional - Set of strings corresponding to missing data

214

filling_values: variable or None, optional - Set of values to be used as default when the data are missing

215

usecols: sequence or None, optional - Which columns to read

216

names: {None, True, str, sequence}, optional - Names for the columns

217

excludelist: sequence, optional - List of names to exclude

218

deletechars: str, optional - Characters to remove from the field names

219

defaultfmt: str, optional - Format used to define the field names

220

autostrip: bool, optional - Whether to automatically strip whitespaces from the values

221

replace_space: char, optional - Character(s) used in replacement of white spaces in the field names

222

case_sensitive: {True, False, 'upper', 'lower'}, optional - If True, field names are case sensitive

223

unpack: bool, optional - If True, return data in separate variables

224

invalid_raise: bool, optional - If True, an exception is raised if an inconsistency is detected in the number of columns

225

max_rows: int, optional - Maximum number of rows to read

226

encoding: str, optional - Encoding used to decode the inputfile

227

"""

228

```

229

230

### Range Generation

231

232

Functions for creating arrays with evenly or logarithmically spaced values.

233

234

```python { .api }

235

def arange(start, stop=None, step=1, dtype=None):

236

"""

237

Return evenly spaced values within a given interval.

238

239

Parameters:

240

start: number, optional - Start of interval (default is 0)

241

stop: number - End of interval (not included)

242

step: number, optional - Spacing between values (default is 1)

243

dtype: dtype, optional - Type of the output array

244

"""

245

246

def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0):

247

"""

248

Return evenly spaced numbers over a specified interval.

249

250

Parameters:

251

start: array_like - Starting value of the sequence

252

stop: array_like - End value of the sequence

253

num: int, optional - Number of samples to generate (default is 50)

254

endpoint: bool, optional - If True, stop is the last sample

255

retstep: bool, optional - If True, return (samples, step)

256

dtype: dtype, optional - Type of the output array

257

axis: int, optional - Axis in the result to store the samples

258

"""

259

260

def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0):

261

"""

262

Return numbers spaced evenly on a log scale.

263

264

Parameters:

265

start: array_like - Base**start is the starting value of the sequence

266

stop: array_like - Base**stop is the final value of the sequence

267

num: int, optional - Number of samples to generate (default is 50)

268

endpoint: bool, optional - If True, stop is the last sample

269

base: array_like, optional - Base of the log space (default is 10.0)

270

dtype: dtype, optional - Type of the output array

271

axis: int, optional - Axis in the result to store the samples

272

"""

273

274

def meshgrid(*xi, copy=True, sparse=False, indexing='xy'):

275

"""

276

Return coordinate matrices from coordinate vectors.

277

278

Parameters:

279

xi: array_like - 1-D arrays representing the coordinates of a grid

280

copy: bool, optional - If False, a view into the original arrays are returned

281

sparse: bool, optional - If True, return a sparse grid instead of a dense one

282

indexing: {'xy', 'ij'}, optional - Cartesian ('xy', default) or matrix ('ij') indexing of output

283

"""

284

```

285

286

### Matrix Creation

287

288

Specialized functions for creating matrices and diagonal arrays.

289

290

```python { .api }

291

def diag(v, k=0):

292

"""

293

Extract a diagonal or construct a diagonal array.

294

295

Parameters:

296

v: array_like - If v is a 2-D array, return its k-th diagonal. If v is 1-D, return a 2-D array with v on the k-th diagonal

297

k: int, optional - Diagonal offset

298

"""

299

300

def diagflat(v, k=0):

301

"""

302

Create a two-dimensional array with the flattened input as a diagonal.

303

304

Parameters:

305

v: array_like - Input data, which is flattened and set as the k-th diagonal of the output

306

k: int, optional - Diagonal offset

307

"""

308

309

def tri(N, M=None, k=0, dtype=float):

310

"""

311

An array with ones at and below the given diagonal and zeros elsewhere.

312

313

Parameters:

314

N: int - Number of rows in the array

315

M: int, optional - Number of columns in the array (default equals N)

316

k: int, optional - Sub-diagonal at and below which the array is filled

317

dtype: dtype, optional - Data type of the returned array

318

"""

319

320

def tril(m, k=0):

321

"""

322

Lower triangle of an array.

323

324

Parameters:

325

m: array_like - Input array

326

k: int, optional - Diagonal above which to zero elements

327

"""

328

329

def triu(m, k=0):

330

"""

331

Upper triangle of an array.

332

333

Parameters:

334

m: array_like - Input array

335

k: int, optional - Diagonal below which to zero elements

336

"""

337

338

def vander(x, N=None, increasing=False):

339

"""

340

Generate a Vandermonde matrix.

341

342

Parameters:

343

x: array_like - 1-D input array

344

N: int, optional - Number of columns in the output (default is len(x))

345

increasing: bool, optional - Order of the powers of the columns

346

"""

347

```

348

349

### Shape Manipulation

350

351

Functions for examining and manipulating array shapes and dimensions.

352

353

```python { .api }

354

def shape(a):

355

"""

356

Return the shape of an array.

357

358

Parameters:

359

a: array_like - Input array

360

"""

361

362

def ravel(a, order='C'):

363

"""

364

Return a contiguous flattened array.

365

366

Parameters:

367

a: array_like - Input array

368

order: {'C','F', 'A', 'K'}, optional - Memory layout

369

"""

370

371

def reshape(a, newshape, order='C'):

372

"""

373

Gives a new shape to an array without changing its data.

374

375

Parameters:

376

a: array_like - Array to be reshaped

377

newshape: int or tuple of ints - New shape should be compatible with the original shape

378

order: {'C', 'F', 'A'}, optional - Read the elements using this index order

379

"""

380

381

def resize(a, new_shape):

382

"""

383

Return a new array with the specified shape.

384

385

Parameters:

386

a: array_like - Array to be resized

387

new_shape: int or tuple of ints - Shape of resized array

388

"""

389

```

390

391

### Transpose Operations

392

393

Functions for rearranging array axes and dimensions.

394

395

```python { .api }

396

def moveaxis(a, source, destination):

397

"""

398

Move axes of an array to new positions.

399

400

Parameters:

401

a: ndarray - Array whose axes should be reordered

402

source: int or sequence of int - Original positions of the axes to move

403

destination: int or sequence of int - Destination positions for each of the original axes

404

"""

405

406

def rollaxis(a, axis, start=0):

407

"""

408

Roll the specified axis backwards, until it lies in a given position.

409

410

Parameters:

411

a: ndarray - Input array

412

axis: int - Axis to be rolled

413

start: int, optional - Position where the rolled axis starts (default is 0)

414

"""

415

416

def swapaxes(a, axis1, axis2):

417

"""

418

Interchange two axes of an array.

419

420

Parameters:

421

a: array_like - Input array

422

axis1: int - First axis

423

axis2: int - Second axis

424

"""

425

426

def transpose(a, axes=None):

427

"""

428

Reverse or permute the axes of an array.

429

430

Parameters:

431

a: array_like - Input array

432

axes: tuple or list of ints, optional - If specified, it must be a tuple or list which contains a permutation of [0,1,..,N-1] where N is the number of axes of a

433

"""

434

```

435

436

### Dimension Manipulation

437

438

Functions for adding, removing, and broadcasting array dimensions.

439

440

```python { .api }

441

def atleast_1d(*arys):

442

"""

443

Convert inputs to arrays with at least one dimension.

444

445

Parameters:

446

arys: array_like - One or more input arrays

447

"""

448

449

def atleast_2d(*arys):

450

"""

451

View inputs as arrays with at least two dimensions.

452

453

Parameters:

454

arys: array_like - One or more input arrays

455

"""

456

457

def atleast_3d(*arys):

458

"""

459

View inputs as arrays with at least three dimensions.

460

461

Parameters:

462

arys: array_like - One or more input arrays

463

"""

464

465

def broadcast(*args):

466

"""

467

Produce an object which mimics broadcasting.

468

469

Parameters:

470

args: array_likes - Input arrays

471

"""

472

473

def broadcast_arrays(*args):

474

"""

475

Broadcast any number of arrays against each other.

476

477

Parameters:

478

args: array_likes - Input arrays to broadcast

479

"""

480

481

def broadcast_to(array, shape, subok=False):

482

"""

483

Broadcast an array to a new shape.

484

485

Parameters:

486

array: array_like - Array to broadcast

487

shape: tuple - Shape of the desired array

488

subok: bool, optional - If True, then sub-classes will be passed-through

489

"""

490

491

def expand_dims(a, axis):

492

"""

493

Expand the shape of an array.

494

495

Parameters:

496

a: array_like - Input array

497

axis: int or tuple of ints - Position in the expanded axes where the new axis (or axes) is placed

498

"""

499

500

def squeeze(a, axis=None):

501

"""

502

Remove single-dimensional entries from the shape of an array.

503

504

Parameters:

505

a: array_like - Input data

506

axis: None or int or tuple of ints, optional - Selects a subset of the single-dimensional entries in the shape

507

"""

508

```

509

510

### Joining Arrays

511

512

Functions for combining multiple arrays along various axes.

513

514

```python { .api }

515

def concatenate(arrays, axis=0, out=None):

516

"""

517

Join a sequence of arrays along an existing axis.

518

519

Parameters:

520

arrays: sequence of array_like - Arrays must have the same shape, except in the dimension corresponding to axis

521

axis: int, optional - Axis along which the arrays will be joined (default is 0)

522

out: ndarray, optional - If provided, the destination to place the result

523

"""

524

525

def stack(arrays, axis=0, out=None):

526

"""

527

Join a sequence of arrays along a new axis.

528

529

Parameters:

530

arrays: sequence of array_like - Each array must have the same shape

531

axis: int, optional - Axis in the result array along which the input arrays are stacked

532

out: ndarray, optional - If provided, the destination to place the result

533

"""

534

535

def vstack(tup):

536

"""

537

Stack arrays in sequence vertically (row wise).

538

539

Parameters:

540

tup: sequence of ndarrays - Arrays to stack

541

"""

542

543

def hstack(tup):

544

"""

545

Stack arrays in sequence horizontally (column wise).

546

547

Parameters:

548

tup: sequence of ndarrays - Arrays to stack

549

"""

550

551

def dstack(tup):

552

"""

553

Stack arrays in sequence depth wise (along third axis).

554

555

Parameters:

556

tup: sequence of arrays - Arrays to stack

557

"""

558

559

def column_stack(tup):

560

"""

561

Stack 1-D arrays as columns into a 2-D array.

562

563

Parameters:

564

tup: sequence of 1-D or 2-D arrays - Arrays to stack

565

"""

566

```

567

568

### Splitting Arrays

569

570

Functions for dividing arrays into sub-arrays along various axes.

571

572

```python { .api }

573

def split(ary, indices_or_sections, axis=0):

574

"""

575

Split an array into multiple sub-arrays as views into ary.

576

577

Parameters:

578

ary: ndarray - Array to be divided into sub-arrays

579

indices_or_sections: int or 1-D array - If int, N equal sub-arrays are created. If 1-D array of sorted integers, entries indicate where along axis the array is split

580

axis: int, optional - Axis along which to split (default is 0)

581

"""

582

583

def array_split(ary, indices_or_sections, axis=0):

584

"""

585

Split an array into multiple sub-arrays.

586

587

Parameters:

588

ary: ndarray - Array to be divided into sub-arrays

589

indices_or_sections: int or 1-D array - If int, N sub-arrays of equal or near-equal size are created. If 1-D array, entries indicate split points

590

axis: int, optional - Axis along which to split (default is 0)

591

"""

592

593

def hsplit(ary, indices_or_sections):

594

"""

595

Split an array into multiple sub-arrays horizontally (column-wise).

596

597

Parameters:

598

ary: ndarray - Array to be divided into sub-arrays

599

indices_or_sections: int or 1-D array - Split specification

600

"""

601

602

def vsplit(ary, indices_or_sections):

603

"""

604

Split an array into multiple sub-arrays vertically (row-wise).

605

606

Parameters:

607

ary: ndarray - Array to be divided into sub-arrays

608

indices_or_sections: int or 1-D array - Split specification

609

"""

610

611

def dsplit(ary, indices_or_sections):

612

"""

613

Split array into multiple sub-arrays along the 3rd axis (depth).

614

615

Parameters:

616

ary: ndarray - Array to be divided into sub-arrays

617

indices_or_sections: int or 1-D array - Split specification

618

"""

619

```

620

621

### Tiling and Repeating

622

623

Functions for repeating and tiling array elements and patterns.

624

625

```python { .api }

626

def tile(A, reps):

627

"""

628

Construct an array by repeating A the number of times given by reps.

629

630

Parameters:

631

A: array_like - Input array

632

reps: array_like - Number of repetitions of A along each axis

633

"""

634

635

def repeat(a, repeats, axis=None):

636

"""

637

Repeat elements of an array.

638

639

Parameters:

640

a: array_like - Input array

641

repeats: int or array of ints - Number of repetitions for each element

642

axis: int, optional - Axis along which to repeat values

643

"""

644

```

645

646

### Adding and Removing Elements

647

648

Functions for modifying arrays by adding or removing elements.

649

650

```python { .api }

651

def append(arr, values, axis=None):

652

"""

653

Append values to the end of an array.

654

655

Parameters:

656

arr: array_like - Values are appended to a copy of this array

657

values: array_like - Values to append to arr

658

axis: int, optional - Axis along which values are appended

659

"""

660

661

def delete(arr, obj, axis=None):

662

"""

663

Return a new array with sub-arrays along an axis deleted.

664

665

Parameters:

666

arr: array_like - Input array

667

obj: int, slice or array of ints - Indicate indices of sub-arrays to remove along the specified axis

668

axis: int, optional - Axis along which to delete the subarray defined by obj

669

"""

670

671

def unique(ar, return_index=False, return_inverse=False, return_counts=False, axis=None):

672

"""

673

Find the unique elements of an array.

674

675

Parameters:

676

ar: array_like - Input array

677

return_index: bool, optional - If True, also return the indices of ar that result in the unique array

678

return_inverse: bool, optional - If True, also return the indices of the unique array that can be used to reconstruct ar

679

return_counts: bool, optional - If True, also return the number of times each unique item appears in ar

680

axis: int, optional - The axis to operate on

681

"""

682

683

def trim_zeros(filt, trim='fb'):

684

"""

685

Trim the leading and/or trailing zeros from a 1-D array or sequence.

686

687

Parameters:

688

filt: 1-D array or sequence - Input array

689

trim: str, optional - A string with 'f' representing trim from front and 'b' to trim from back

690

"""

691

```

692

693

### Rearranging Elements

694

695

Functions for rearranging array elements and changing element order.

696

697

```python { .api }

698

def flip(m, axis=None):

699

"""

700

Reverse the order of elements in an array along the given axis.

701

702

Parameters:

703

m: array_like - Input array

704

axis: None or int or tuple of ints, optional - Axis or axes along which to flip over

705

"""

706

707

def fliplr(m):

708

"""

709

Flip array in the left/right direction.

710

711

Parameters:

712

m: array_like - Input array, must be at least 2-D

713

"""

714

715

def flipud(m):

716

"""

717

Flip array in the up/down direction.

718

719

Parameters:

720

m: array_like - Input array

721

"""

722

723

def roll(a, shift, axis=None):

724

"""

725

Roll array elements along a given axis.

726

727

Parameters:

728

a: array_like - Input array

729

shift: int or array_like - Number of places by which elements are shifted

730

axis: int or array_like, optional - Axis or axes along which elements are shifted

731

"""

732

733

def rot90(m, k=1, axes=(0, 1)):

734

"""

735

Rotate an array by 90 degrees in the plane specified by axes.

736

737

Parameters:

738

m: array_like - Array of two or more dimensions

739

k: int, optional - Number of times the array is rotated by 90 degrees

740

axes: array_like - Axes that define the plane of rotation (default is first two axes)

741

"""

742

```

743

744

## Usage Examples

745

746

```python

747

import cupy as cp

748

749

# Array creation

750

gpu_array = cp.array([1, 2, 3, 4])

751

zeros_matrix = cp.zeros((1000, 1000))

752

identity = cp.eye(5)

753

754

# Shape manipulation

755

reshaped = cp.reshape(gpu_array, (2, 2))

756

flattened = cp.ravel(zeros_matrix)

757

758

# Joining arrays

759

a = cp.array([[1, 2], [3, 4]])

760

b = cp.array([[5, 6]])

761

vstacked = cp.vstack([a, b])

762

hstacked = cp.hstack([a, a])

763

764

# Array splitting

765

parts = cp.split(gpu_array, 2)

766

hsplit_result = cp.hsplit(vstacked, 2)

767

768

# Element operations

769

repeated = cp.repeat(gpu_array, 2)

770

tiled = cp.tile(gpu_array, (2, 1))

771

unique_vals = cp.unique(cp.array([1, 2, 2, 3, 3, 3]))

772

```

773

774

Array operations in CuPy provide the foundation for GPU-accelerated computation, enabling efficient manipulation of large datasets with NumPy-compatible interfaces while leveraging the parallel processing power of modern GPUs.